Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在I'之后自动选择检查表项目;已选择具有相关主键的下拉列表项_C#_Asp.net_Drop Down Menu - Fatal编程技术网

C# 在I'之后自动选择检查表项目;已选择具有相关主键的下拉列表项

C# 在I'之后自动选择检查表项目;已选择具有相关主键的下拉列表项,c#,asp.net,drop-down-menu,C#,Asp.net,Drop Down Menu,我需要一些关于ddlstore\u selectedindexchange事件下的代码的帮助。我试图让员工和客户检查表自动检查他们的外键Id是否等于门店主键Id。我不知道应该在if语句中添加什么 protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { using (StuffContainer context = new StuffContainer())

我需要一些关于ddlstore\u selectedindexchange事件下的代码的帮助。我试图让员工和客户检查表自动检查他们的外键Id是否等于门店主键Id。我不知道应该在if语句中添加什么

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        using (StuffContainer context = new StuffContainer())
        {
            ddlstore.DataSource = context.Stores.ToList();
            ddlstore.DataTextField = "Name";
            ddlstore.DataValueField = "Id";
            ddlstore.DataBind();

            chkemp.DataSource = context.Customers.ToList();
            chkemp.DataTextField = "FName";
            chkemp.DataValueField = "Id";
            chkemp.DataBind();

            chkcust.DataSource = context.Employees.ToList();
            chkcust.DataTextField = "FName";
            chkcust.DataValueField = "Id";
        }
    }
}

protected void ddlstore_SelectedIndexChanged(object sender, EventArgs e)
{
    int storeId = int.Parse(ddlstore.SelectedValue);

    using (StuffContainer context = new StuffContainer())
    {
        List<Employee> employees = context.Employees.ToList();

        var employee = context.Employees.Where(x => x.StoreId == storeId);

        foreach(Employee item in employees)
        {
           if()
           {

           }
        }
    }
}
受保护的无效页面加载(对象发送方,事件参数e)
{
如果(!Page.IsPostBack)
{
使用(StuffContainer context=new StuffContainer())
{
ddlstore.DataSource=context.Stores.ToList();
ddlstore.DataTextField=“Name”;
ddlstore.DataValueField=“Id”;
ddlstore.DataBind();
chkemp.DataSource=context.Customers.ToList();
chkemp.DataTextField=“FName”;
chkemp.DataValueField=“Id”;
chkemp.DataBind();
chkcust.DataSource=context.Employees.ToList();
chkcust.DataTextField=“FName”;
chkcust.DataValueField=“Id”;
}
}
}
受保护的无效ddlstore\u SelectedIndexChanged(对象发送方,事件参数e)
{
int storeId=int.Parse(ddlstore.SelectedValue);
使用(StuffContainer context=new StuffContainer())
{
List employees=context.employees.ToList();
var employee=context.Employees.Where(x=>x.StoreId==StoreId);
foreach(员工中的员工项目)
{
if()
{
}
}
}
}
protected void ddlstore_SelectedIndexChanged(object sender, EventArgs e)
{
    int storeId = int.Parse(ddlstore.SelectedValue);

    using (StuffContainer context = new StuffContainer())
    {
        var employees = context.Employees
           .Where(x => x.StoreId == storeId)
           .Select(x => x.Id).ToList();
        var customers = context.Customers
           .Where(x => x.StoreId == storeId)
           .Select(x => x.Id).ToList();

        foreach(ListItem item in chkemp.Items)
            item.Selected = employees.Contains(int.Parse(item.Value));

        foreach(ListItem item in chkcust.Items)
            item.Selected = customers.Contains(int.Parse(item.Value));
    }
}