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