This is a migrated thread and some comments may be shown as answers.

ItemDataBound when using DetailTables

1 Answer 411 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Morten
Top achievements
Rank 2
Iron
Iron
Veteran
Morten asked on 20 Aug 2010, 04:21 PM
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:
<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

DetailTableDataBind
Private 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 Sub

Error 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


1 Answer, 1 is accepted

Sort by
0
Accepted
Cori
Top achievements
Rank 2
answered on 20 Aug 2010, 08:25 PM
Hello,

You should be able to determine if it's a DetailTable by accessing the e.Item.OwnerTableView.Name property and then checking if it macthes the DetailTable name you're looking for.

I hope that helps.
Tags
Grid
Asked by
Morten
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Cori
Top achievements
Rank 2
Share this question
or