Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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# 将值分配给网格中的DropDownList_C#_Asp.net - Fatal编程技术网

C# 将值分配给网格中的DropDownList

C# 将值分配给网格中的DropDownList,c#,asp.net,C#,Asp.net,我在网格中有一个DropDownList,我有一个foreach循环,它循环查询并匹配数据,并填充该行上每一行的下拉列表。但它将所有数据放在同一个下拉列表中。因此,第1行、第2行、第3行等都被合并到dropdownlist中。我试图使它在第1行dropdlownlist中包含第1行和第2行的信息,dropdownlist包含第2行的信息,依此类推 到目前为止,我有: protected void grdExceptions_ItemDataBound(object sender, GridIte

我在网格中有一个DropDownList,我有一个foreach循环,它循环查询并匹配数据,并填充该行上每一行的下拉列表。但它将所有数据放在同一个下拉列表中。因此,第1行、第2行、第3行等都被合并到dropdownlist中。我试图使它在第1行dropdlownlist中包含第1行和第2行的信息,dropdownlist包含第2行的信息,依此类推

到目前为止,我有:

protected void grdExceptions_ItemDataBound(object sender, GridItemEventArgs e)
  {
    var linqContext = new DataClassesDataContext();
    var sessionleads = from q in linqContext.Leads where q.SessionID == SessionId orderby q.RowIndex select q;

    if (e.Item is GridDataItem)
      {
        foreach(var p in sessionleads)
          {
            var lQuery = (from a in gServiceContext.CreateQuery("account") where (a["name"].Equals(p.AccountName) &&
                                         a["address1_postalcode"].Equals(p.ZipCode) &&
                                         a["address1_stateorprovince"].Equals(p.State)) ||
                                        (a["address1_line1"].Equals(p.Address1) &&
                                         a["address1_postalcode"].Equals(p.ZipCode) &&
                                         a["address1_city"].Equals(p.City))
          select new
          {
            Name = !a.Contains("name") ? string.Empty : a["name"]
          });
          foreach (var a in lQuery)
            {
              ((e.Item as GridDataItem)["Account"].FindControl("AccountList") as DropDownList).Items.Add(new ListItem(a.Name.ToString()));
            }
          }
    }
  }
我在网格的ItemTemplate中有一个DropDownlist。因此,对于第一行,我希望找到与第一行的drop downlist匹配的内容,对于第二行,我希望找到与第二行的drop downlist匹配的内容,以此类推

我做错了什么


谢谢

当ItemDataBound为每一新行激发时,您似乎期望SessionId会有所不同,但它只是保持不变。是否有其他筛选条件可以添加到where子句中?或者以某种方式更新每一新行的SessionId?

您似乎没有任何代码根据当前项约束下拉列表内容,因此网格中每一行的查询结果都是相同的。如何约束它?这就是我无法理解的。你需要先问问自己,每行上有哪些数据应该限制下拉框的内容。一旦你有了这些信息,你应该能够从e.Item中提取这些信息并将其添加到你的查询中。实际上,它是基于p。sessionLeads中的p是输出到每行的数据。它似乎只是对所有数据使用了一个下拉列表,而不是为每一行创建一个新的下拉列表。您是否在网格中的某个位置看到了大量重复的下拉列表或一个过多的列表?