In a RadGrid I have one DetailTable that is populated in the DetailTableDataBind event. In the ItemDataBound I set some attributes which works fine until the expand icon is clicked (see error below).
How do I detect (in the ItemDataBound event) that it is the DetailTable that is being databound?
Grid structure:
ItemDataBound
Error in line 61
How do I detect (in the ItemDataBound event) that it is the DetailTable that is being databound?
Grid structure:
<telerik:RadGrid ID="rg" runat="server" AutoGenerateColumns="False"> <MasterTableView DataKeyNames="key"> <Columns> <telerik:GridBoundColumn DataField="key" HeaderText="key" UniqueName="key" /> <telerik:GridBoundColumn DataField="value" HeaderText="value" UniqueName="value" /> <telerik:GridTemplateColumn UniqueName="SelectColumn" AllowFiltering="false"> <HeaderTemplate><asp:CheckBox runat="server" ID="chkAll" ToolTip="Toggle all" /></HeaderTemplate> <ItemTemplate><asp:CheckBox runat="server" ID="chkItem" /></ItemTemplate> </telerik:GridTemplateColumn> </Columns> <DetailTables> <telerik:GridTableView AutoGenerateColumns="true" Name="details" HierarchyLoadMode="ServerOnDemand" /> </DetailTables> </MasterTableView></telerik:RadGrid>ItemDataBound
Protected Sub rg_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) _ Handles rg.ItemDataBound Select Case e.Item.ItemType Case GridItemType.Header Dim ghi As GridHeaderItem = CType(e.Item, GridHeaderItem) Dim chkAll As CheckBox = ghi.FindControl("chkAll") chkAll.Attributes.Add("onclick", "TogglePending(this);") Case GridItemType.AlternatingItem, GridItemType.Item Dim gdi As GridDataItem = CType(e.Item, GridDataItem) Dim ce As Data.DataRowView = CType(e.Item.DataItem, Data.DataRowView) Dim chkItem As CheckBox = gdi.FindControl("chkItem") chkItem.Attributes.Add("onclick", String.Format("chkItem_CheckedChanged(this, '{0}');", e.Item.ItemIndex)) End Select
End Sub DetailTableDataBindPrivate Sub rg_DetailTableDataBind(ByVal source As Object, ByVal e As GridDetailTableDataBindEventArgs) Handles rg.DetailTableDataBind Dim gdi As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem) e.DetailTableView.DataSource = getDetails(gdi("key").Text)End SubError in line 61
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error: Line 59: Line 60: Dim chkAll As CheckBox = ghi.FindControl("chkAll")Line 61: chkAll.Attributes.Add("onclick", "TogglePending(this);")Line 62: Line 63: Case GridItemType.AlternatingItem, GridItemType.Item