Label Search in GridTableView (RadGrid)

I have a hierarchical Telerik RadGrid that sometimes contains child records that are empty. To do this, I want to overwrite the default text โ€œNo child records to displayโ€ with the user's specific language.

So I can do this:

<telerik:RadGrid ID ="SettingsGrid" ... /> <mastertableview ... /> <DetailTables> <telerik:GridTableView ... /> <asp:Label ID="NoRecordLabel" runat="server" Text="whatever"/></div></NoRecordsTemplate> 

What causes the text "anything" when it should appear.

But I obviously want to do it dynamically, but I failed in two ways:

1) Link to my .resx file in a .ascx file. I import this namespace and reference a specific resource as such:

 Text="<%$ Resx:SiteTextResources.Globals_Close %>" 

(This works in other files in the same solution)

But this only creates empty text.

2) I was unable to get the Label programmatically from the code behind. I looked at this: http://www.telerik.com/community/forums/aspnet-ajax/grid/how-to-access-controls-in-norecordstemplate.aspx , but did not get this approach to work, as I just I can not find the shortcut. I get an OutOfBoundsException, which I suppose means the GetItems () method returns null.

Any ideas? It would be very grateful!

+4
source share
1 answer

Try using the code snippet below. Let me know if there is any problem.

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(); } } } } 
+3
source

Source: https://habr.com/ru/post/1501501/


All Articles