0

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 Answers 2

2

set DataKeyNames to your key name

For example:

<asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        autogenerateselectbutton="true"    
        datakeynames="CustomerID"
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for the right answer, but as pertaining to the question: add GridView1.DataKeyNames = "Key"; just before the DataBind()
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.