Problem with HierarGrid dgi.DataItem = nothing
Posted on 2004-10-26
I have been attempting to implement Denis Bauers Hierargid for a project that I am currently working on.
Everything goes fine, if I use templatedatamode = singlerow.
I can happily bind the row that is passed to the user control to a text box. I do however need to use templatedatamode = table, to pass all of the rows associated with the detail block to the webcontrol, so that I can use a nested datagrid. This is where my problems start :(
The dataitem of the datagriditem is always nothing, I therefore can not then cast it into a dataset, for use with my datagrid. I have seen lots of examples of invalid casts - I do not get that however - it's simply that the datagriditem is always nothing.
Below is my code - I have included both the area where I set the template, and the code for the ascx web control, and i'd really appreciate any help that anyone can offer - as i've completly hit a brick wall with it at the moment.
Please note - I followed Denis's tutorial from ASPAlliance as closely as I could the only difference being that my dataset is populated from my database. Also I know that each row does have child rows - as it works if I dont use table mode but rather singlerow.
Private Sub DG1_TemplateSelection(ByVal sender As Object, ByVal e As DBauer.Web.UI.WebControls.HierarGridTemplateSelectionEventArgs) Handles DG1.TemplateSelection
e.TemplateFilename = "Detail.ascx"
and now for the web control detail.ascx
Public Class Detail
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dgi As DataGridItem = CType(Me.BindingContainer, DataGridItem)
Dim ds As DataSet = CType(dgi.DataItem, DataSet)
DataGrid1.DataSource = ds
DataGrid1.DataMember = ds.Tables(0).TableName
Catch ex As Exception