我有一个radgrid,在其DetailItemTemplate中包含另一个;如下面的代码所示:
<telerik:RadGrid ID="Radgrid1" runat="server" AutoGenerateColumns="false"
OnNeedDataSource="Radgrid1_NeedDataSource" OnItemDataBound="Radgrid1_ItemDataBound">
<MasterTableView AutoGenerateColumns="false" DataKeyNames="ID" GroupLoadMode="Client">
<Columns>
<telerik:GridBoundColumn HeaderText="Name" DataField="NAME" />
</Columns>
<DetailItemTemplate>
<telerik:RadGrid ID="Radgrid2" runat="server" AutoGenerateColumns="false">
<MasterTableView AutoGenerateColumns="false" DataKeyNames="Number"
GroupLoadMode="Client">
<Columns>
<telerik:GridBoundColumn HeaderText="Number" DataField="NUMBER" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
</DetailItemTemplate>
</MasterTableView>
</telerik:RadGrid>
将DataTable绑定到radgrid2作为DataSource的最佳方法是什么?
答案 0 :(得分:0)
请尝试使用以下代码段。
<强> ASPX 强>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
AllowPaging="true" AllowSorting="true" OnDetailTableDataBind="RadGrid1_DetailTableDataBind">
<MasterTableView DataKeyNames="ID" CommandItemDisplay="Top">
<Columns>
<telerik:GridEditCommandColumn>
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID"></telerik:GridBoundColumn>
</Columns>
<DetailTables>
<telerik:GridTableView Name="Child1">
<Columns>
<telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name"></telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
</MasterTableView>
</telerik:RadGrid>
<强> ASPX.CS 强>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data1 = new[] {
new { ID = 1, Name ="Name_1",Customdate = DateTime.Now},
new { ID = 2, Name = "Name_2",Customdate = DateTime.Now},
new { ID = 3, Name = "Name_3",Customdate = DateTime.Now},
new { ID = 4, Name = "Name_4",Customdate = DateTime.Now},
new { ID = 5, Name = "Name_5",Customdate = DateTime.Now}
};
RadGrid1.DataSource = data1;
}
protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
dynamic data1 = new[] {
new { ID = 1, Name =DateTime.Now.ToString(),Customdate = DateTime.Now},
new { ID = 2, Name = "Name_2",Customdate = DateTime.Now},
new { ID = 3, Name = "Name_3",Customdate = DateTime.Now},
new { ID = 4, Name = "Name_4",Customdate = DateTime.Now},
new { ID = 5, Name = "Name_5",Customdate = DateTime.Now}
};
e.DetailTableView.DataSource = data1;
}