views:

67

answers:

2

I group my data by length as follows

int[] a = { 1, 2, 3,45,45,100,566};

var result =
 a.GroupBy(x => x.ToString().Length).
 Select(d => new { Key = d.Key, Grp = d });

My BulletedList is nested in GridView(placed as template field) to display the items,What is the way to bind the BulletedList when GridView displays "Key".

 GridView1.DataSource = result;
 GridView1.DataBind();
+2  A: 

set DataKeyNames to your key name

For example:

<asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        autogenerateselectbutton="true"    
        datakeynames="CustomerID"
Chris Ballance
+1 for the right answer, but as pertaining to the question: add GridView1.DataKeyNames = "Key"; just before the DataBind()
Jim Schubert
A: 

Binding to a bulleted list within a gridview (works similarly for any control, of course)

 void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
  {

    if(e.Row.RowType == DataControlRowType.DataRow)
    {
      RadioButtonList list = (RadioButtonList)e.Row.FindControl("rbList");
      if(list != null)
      {
         list.DataSource = mysource;
         list.DataBind();
      }
    }
   }

Make sure you add the event to the GridView.

Jim Schubert