使用Where语句从数据库中绑定数据中继器
本文关键字:绑定 数据 中继器 数据库 Where 语句 使用 | 更新日期: 2023-09-27 18:01:50
大家好,感谢大家的阅读。
是否有一些方法,我可以绑定我的中继器只列出包含等于从我的QueryString单词/数字的东西的行?
这里是一个例子,我的导航Url与QueryString在它:/Store.aspx?id = 12
我是否可以将中继器绑定为加载Column等于12的所有行
private void BindItems()
{
rpStore.DataSource = Menues.GetAll();
rpStore.DataBind();
}
My menus .cs Class:
public static List<Item> GetAll()
{
using (Scooterfrøen_Entities db = new Scooterfrøen_Entities())
{
return db.Item.ToList();
}
}
顺便说一句,我正在使用实体框架,所以解决方案是预防,但不需要。
谢谢。
创建如下函数:
public static List<Item> GetById(int id)
{
using (Scooterfrøen_Entities db = new Scooterfrøen_Entities())
{
var listOfItemsById = from i in db.Item
where i.Id == id
select i;
return listOfItemsById.ToList();
}
}
在store中加载页面时。aspx获取id:
int id = Convert.ToInt32(Request.QueryString["id"]);