简体   繁体   English

使用Where语句从数据库中绑定转发器

[英]Databind repeater from database with Where statement

Hello and thanks for reading this. 您好,感谢您阅读本文。

Is there some way that I can databind my Repeater to list only the rows that contains somethings that equal a word/number from my QueryString? 有什么方法可以对Repeater进行数据绑定,以仅列出包含与我的QueryString中的单词/数字相等的内容的行?

Here is an Example of my Nav Url with a QueryString in it : /Store.aspx?id=12 这是其中带有QueryString的Nav Url的示例: /Store.aspx?id=12

Can I bind the repeater to Load all rows where the Column is equal to 12 我可以将转发器绑定到Column等于12的所有行吗

private void BindItems()
{
    rpStore.DataSource = Menues.GetAll();
    rpStore.DataBind();
}

My Menues.cs Class: 我的Menues.cs类别:

public static List<Item> GetAll()
{
    using (Scooterfrøen_Entities db = new Scooterfrøen_Entities())
    {
        return db.Item.ToList();
    }
}

Btw I'm using Entity FrameWork, so a solution with that is prefence but not needed. 顺便说一句,我正在使用Entity FrameWork,因此有一个解决方案是优先考虑的,但并非必需。

Thanks alot. 非常感谢。

Create a function like this: 创建一个这样的函数:

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();
    }
}

When the page loads in store.aspx get the id : 当页面加载到store.aspx中时,获取ID:

int id = Convert.ToInt32(Request.QueryString["id"]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM