Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem with HierarGrid dgi.DataItem = nothing

Posted on 2004-10-26
6
Medium Priority
?
378 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:LindzK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 12411529
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
 
LVL 33

Expert Comment

by:raterus
ID: 12411633
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
 
LVL 5

Author Comment

by:LindzK
ID: 12411727
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
 
LVL 5

Author Comment

by:LindzK
ID: 12411819
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12632543
Closed, 500 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question