Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
I need some help with a 'drill-down' user control that I'm creating. I think I'm nearly there.
 
What I am trying to acheive is a hierarchical grid of staff;
 
Manager1
Manager2
Manager3
 
Clicking on Manager1 shows:
 
Manager1
-LineManager1
-LineManager2
Manager2
Manager3
 
Clicking on LineManager1 shows:
 
Manager1
-LineManager1
--Staff1
--Staff2
--Staff3
-LineManager2
Manager2
Manager3
 
I have simplified the information returned here, but each line will contain a few colums worth of data.
 
I dont want to use a treeview because of the few columns of data issue and because I don't want to load all of the staff (there will be thousands)
 
I have created a UserControl that contains a Gridview. Each Row of the Gridview contains a LinkButton and a PlaceHolder Control.
 
I have an SQL stored Procedure that returns the data for the list of staff at any given level - this is run using a 'ParentUser' Property of the UserControl.
 
When the LinkButton is clicked I load a new instance of the UserControl and add it to the gridviewrows placeholder:
 
Dim myDL As New UserControls_DLGridItem
Dim myRow As GridViewRow = CType(sender, LinkButton).Parent.Parent
 
myDL = Page.LoadControl("UserControls/DLGriditem.ascx")
myDL.ParentUserCode = CType(sender, LinkButton).CommandArgument
myDL.StartDate = Me.StartDate
CType(myRow.FindControl("Placeholder1"), PlaceHolder).Controls.Add(myDL)
 
I have created a test page and added an instance of the usercontrol. When the page loads it sets the ParentUser Property of the control.
 
So far, so good - the page loads and displays the top level of managers.
Clicking on LinkButton then Loads the next Level (LineManagers) OK.
 
The problem I have is that Clicking the LinkButton on one of the LineManagers does not fire the LinkButton_Click event.
 
Initially the dynamically generated content has disappearing completely after clicking on a LinkButton in the dynamically created control.
 
I added this to the LinkButton_Onclick Event (after I add to the placeholder):
 
Session.Add(CType(myRow.FindControl("Placeholder1"), PlaceHolder).UniqueID, myDL)
 
And this:
 
Protected Sub GridView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PreRender
 
        For Each rw As GridViewRow In Me.GridView1.Rows
            If rw.RowType = DataControlRowType.DataRow Then
                'If there is a usercontrol in session then load it!
                Dim myPlaceholder As PlaceHolder = rw.FindControl("PlaceHolder1")
 
                If Not Session(myPlaceholder.UniqueID) Is Nothing Then
                    myPlaceholder.Controls.Clear()
                    myPlaceholder.Controls.Add(CType(Session(myPlaceholder.UniqueID), UserControls_DLGridItem))
                End If
            End If
        Next
 
    End Sub
 

This stops the dynamically generated controls disappearing but still wont process the LinkButton_Click event on the controls.
 
In other words I can get The LineMangers Loaded, but not their staff!
 
Anyone have any ideas what I am doing wrong?
 
Is there an easier way of doing this?
 
Thanks!
 
Chris
Posted 11-Feb-11 6:38am
Comments
digital man at 14-Feb-11 4:13am
   
You do know that you can load only the records you want to see at any given moment? Populate the tree with only the top parent level and then, using the TreeNodePopulate event (this is on the standard Asp.Net TreeView) you can then populate the child level. Take a look: works pretty well: I've recently used this and it works well (is fast) with large numbers of records.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Thanks digital man,
 
I didn't want to use a treeview because I'm returning a grid-like structure that will need formatted columns.
 
I think I now have this working properly.
 
I moved the code in the gridview1.PreRender to the page Load event and amended it slightly to:
 
For Each rw As GridViewRow In Me.GridView1.Rows
            If rw.RowType = DataControlRowType.DataRow Then
                'If there is a usercontrol in session then load it!
                Dim myPlaceholder As PlaceHolder = rw.FindControl("PlaceHolder1")
                If Not Session(myPlaceholder.UniqueID) Is Nothing Then
                    myPlaceholder.Controls.Clear()
                    Dim myDL As New UserControls_DLGridItem
                    myDL = Page.LoadControl("UserControls/DLGriditem.ascx")
                    myDL.WhichResults = 3
                    myDL.ParentUserCode = CType(Session(myPlaceholder.UniqueID), UserControls_DLGridItem).ParentUserCode
                    myDL.StartDate = CType(Session(myPlaceholder.UniqueID), UserControls_DLGridItem).StartDate
                    myPlaceholder.Controls.Add(myDL)
                 End If
            End If
        Next
 
i.e. I'm re-creating the child control (using Page.LoadControl) rather than simply getting it from the session.
 
Thanks
 
Chris
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Marcin Kozub 265
1 Richard MacCutchan 239
2 OriginalGriff 208
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 15 Feb 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100