请尝试使用以下代码片段。让我知道是否有任何问题。
ASPX
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
OnItemDataBound="RadGrid1_ItemDataBound"
OnDetailTableDataBind="RadGrid1_DetailTableDataBind"
onprerender="RadGrid1_PreRender">
<MasterTableView CommandItemDisplay="Top" DataKeyNames="ID">
<Columns>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
</telerik:GridBoundColumn>
<telerik:GridEditCommandColumn>
</telerik:GridEditCommandColumn>
</Columns>
<DetailTables>
<telerik:GridTableView Name="Child">
<NoRecordsTemplate>
<asp:Label ID="NoRecordLabel" runat="server" Text="whatever" />
</NoRecordsTemplate>
<Columns>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
</telerik:GridBoundColumn>
<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",FileName = "jayesh.jpg"},
new { ID = 2, Name = "Name_2",FileName = "jayesh.jpg"},
new { ID = 3, Name = "Name_3",FileName = "jayesh.jpg"},
new { ID = 4, Name = "Name_4",FileName = "jayesh.jpg"},
new { ID = 5, Name = "Name_5",FileName = "jayesh.jpg"}
};
RadGrid1.DataSource = data1;
}
protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
e.DetailTableView.DataSource = new Object[0];
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{
if (item.HasChildItems && item.Expanded)
{
if (item.ChildItem.NestedTableViews[0].GetItems(GridItemType.NoRecordsItem).Count() > 0)
{
GridNoRecordsItem norecordItem = (GridNoRecordsItem)item.ChildItem.NestedTableViews[0].GetItems(GridItemType.NoRecordsItem)[0];
Label NoRecordLabel = (Label)norecordItem.FindControl("NoRecordLabel");
NoRecordLabel.Text = DateTime.Now.ToString();
}
}
}
}