Assigning Values to DropDownList in Grid
<p>I have a DropDownList in a Grid and I have a foreach loop that loops through a Query and matches data and fills the drop down list for each row on that. But It is putting the data all in the same dropdownlist. So row 1, row 2, row 3, etc. all get combined into the dropdownlist. I am trying to make it so in row 1 dropdlownlist has the info for row 1 and row 2 the dropdownlist has the info for row 2 and so on.</p>

<p>I have this so far:</p>

<pre><code>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) &amp;&amp;
                                         a["address1_postalcode"].Equals(p.ZipCode) &amp;&amp;
                                         a["address1_stateorprovince"].Equals(p.State)) ||
                                        (a["address1_line1"].Equals(p.Address1) &amp;&amp;
                                         a["address1_postalcode"].Equals(p.ZipCode) &amp;&amp;
                                         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()));
            }
          }
    }
  }
</code></pre>

<p>I have a DropDownlist in the ItemTemplate of the Grid. So for the first row I would want whatever matches are found assigned to the drop downlist in the first row, for the second row I would want whatever matches the dropdownlist in the second row, etc.</p>

<p>What am I doing wrong?</p>

<p>Thanks!</p>
