4 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 08 Dec 2009, 04:36 AM
Hello Duy,
Try the following code snippet in order to access the control placed in HeaderTemplate.
ASPX:
CS:
You could use the following code if you want to access the control in ItemDataBound event.
CS:
-Shinu.
Try the following code snippet in order to access the control placed in HeaderTemplate.
ASPX:
| <telerik:GridTemplateColumn UniqueName="Temp"> |
| <ItemTemplate> |
| </ItemTemplate> |
| <HeaderTemplate> |
| <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> |
| </HeaderTemplate> |
| </telerik:GridTemplateColumn> |
CS:
| GridHeaderItem headerItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0]; |
| Label lbl = (Label)headerItem.FindControl("Label1"); |
| lbl.Text = "New Text"; |
You could use the following code if you want to access the control in ItemDataBound event.
CS:
| protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| if (e.Item is GridHeaderItem) |
| { |
| GridHeaderItem headerItem = (GridHeaderItem)e.Item; |
| Label lbl = (Label)headerItem.FindControl("Label1"); |
| lbl.Text = "My Text"; |
| } |
| } |
-Shinu.
0
Duy
Top achievements
Rank 1
answered on 08 Dec 2009, 06:30 AM
Thanks Shinu, I got it.
Cheers,
Duy
Cheers,
Duy
0
Jinson
Top achievements
Rank 1
answered on 19 Feb 2020, 11:50 AM
Hi,
Could you please share the vb.net code for accessing the header template in rowdatabound?
0
Hi Jinson,
Here is the VB version of the code posted by Shinu.
VB
Dim headerItem As GridHeaderItem = CType(RadGrid1.MasterTableView.GetItems(GridItemType.Header)(0), GridHeaderItem)
Dim lbl As Label = CType(headerItem.FindControl("Label1"), Label)
lbl.Text = "New Text"
VB
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)
If TypeOf e.Item Is GridHeaderItem Then
Dim headerItem As GridHeaderItem = CType(e.Item, GridHeaderItem)
Dim lbl As Label = CType(headerItem.FindControl("Label1"), Label)
lbl.Text = "My Text"
End If
End Sub
I would also recommend the Telerik Code Converted we have which is an online tool for converting C# to VB or vice versa, see http://converter.telerik.com/. This could come handy in the future if you're finding examples only in C#.
Kind regards,
Attila Antal
Progress Telerik
Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
