Problem with HierarGrid dgi.DataItem = nothing

Hello,

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"

    End Sub

and now for the web control detail.ascx

Public Class Detail

    Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    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.

        InitializeComponent()

    End Sub

#End Region


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try

            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

            DataGrid1.DataBind()

        Catch ex As Exception

        End Try
       
    End Sub

End Class

LVL 5
LindzKAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

raterusCommented:
You realize how you currently have it, this code runs EVERY time the page loads/postsback.  If you are raising events from the datagrid, they will be erased when you rebind it like this.  I don't know anything about the HierarGrid (doubt anyhere here does), but I do know that people run into problems when they don't wrap their databinding code in page_load like this.  

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Not Page.IsPostBack Then

        Try
            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
            DataGrid1.DataBind()
        Catch ex As Exception
        End Try

        End If
       
    End Sub
0
raterusCommented:
wait wait wait, I just looked at your code...Me.BindingContainer?  That isn't an asp.net object but a winforms object!  Where did you get that?
0
LindzKAuthor Commented:
There is a web control, that you can download from www.asp.net called the Hierargrid.

It enables nested master/detail datagrids, and apart from the detail section - it functions just like a normal datagrid

I do use if not page.ispostback on my main page - where i bind the first table in my dataset to the hierargrid.

I'm sorry - I didnt' post that bit of code, the code I posted is from an ascx page, that you ahve to create which acts as a template for the detail ( second table area ) of the hierargrid.  So, although you dont see if not ispostback in the code I posted - it happens only once, as it's parent grid is formed correctly on the main aspx page.

The hierargrid can either display each child row to it's own template - I did this, and it works correctly
or have one row per child table of the parent rows.  This is where my problems happen.

The code I posted, is taken straight from the tutorial on aspalliance written by the guy who wrote the hierargrid, who happens to also work for mircrosoft in Germany.

I posted this question here - as it seems a lot of people use this grid, and I was sort of hoping someone else who'd used it, may recognise my problem, and have a solution for me.

Sorry if I confused the matter -  by not explaining how I got the code I did.
0
LindzKAuthor Commented:
btw I got the Me.BindingContainer bit from his tutorial, and it doesn't throw any errors or anything when I run through the code, it's just that the dataitem of the datagriditem, is nothing.

I have now managed to do a sort of work around, to get the table out

DataGrid1.DataSource = CType(Me.BindingContainer, DataGridItem).DataItem.DataView.DataViewManager.DataSet.Tables(1)
            DataGrid1.DataBind()

That works fine - it eventually after iterating through a few components ( as you can see above ) it obtains the child datatable from the item that is passed to the asxc template.

This seems rather cumbersome and messy though - and i'm still hoping to find out what the problem is with my implementation of how you are supposed to use this control.  Rather than my messy work around.

I understand that not everyone will have come across the hierargrid control  - but I am still hoping that someone out there, knows how to implement it, and that I can get the solution working as intended.
0
moduloCommented:
Closed, 500 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.