开发者

ASP.NET/C# Linq Binding to GridView

开发者 https://www.devze.com 2022-12-14 04:21 出处:网络
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).

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 => n开发者_运维技巧ew { 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();


set DataKeyNames to your key name

For example:

<asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        autogenerateselectbutton="true"    
        datakeynames="CustomerID"


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号