Hi Mark,
thanks once again for your help, i am creating a differing amount of datagrids based upon a variable specified in a textbox, the user will then click a button and the variable will determine how many datagrids are created. However as the pre init always occurs first the variable won't get past in. I decided to get around this problem by creating the datagrids as an array, on the click event i then add the relevant amount of datagrids to the panel. I have posted the code below
privat sub blahblah (ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
Dim counter1 As Integer
SQLCmd.CommandText = "SELECT count(*) from dept_types"
CountMatch = SQLCmd.ExecuteScalar
SQLCmd.CommandText = "Select rtype, RDescription, sqlcommandtext from Dept_Types"
SQLdr = SQLCmd.ExecuteReader
ReDim Panelbody(CountMatch), paneltitles(CountMatch), Dg(CountMatch), cpe(CountMatch), panelHead(CountMatch)
'Declares the different array controls to be used within the summary screen
'Each expanding panel will need label panel head, panel body, datagrid and expanding collapsible panel
Dim lbl(CountMatch) As Label, lblhead(CountMatch) As Label
Dim TypeCount As Integer
Dim ButtonColumn(CountMatch) As ButtonField, lblb(CountMatch) As Label, RecordsFound As Boolean
sqldatagrid.Connection = SQLConn
counter1 = 1
RecordsFound = False
' For counter1 = 1 To ReferralCountMatch
Do
While (SQLdr.Read())
panelHead(counter1) = New Panel
panelHead(counter1).ID = "pH" & SQLdr("rType")
' Add Label inside header panel to display text
lblhead(counter1) = New Label
lblhead(counter1).ID = "lblHeader" & SQLdr("RType")
panelHead(counter1).Controls.Add(lblhead(counter1))
'Create Body Panel
Panelbody(counter1) = New Panel
Panelbody(counter1).ID = "pB" & counter1
'set up the datagrids
Dg(counter1) = New GridView
Dg(counter1).ID = "dg" & counter1
AddHandler Dg(counter1).RowCommand, AddressOf AllGridView_RowCommand
AddHandler Dg(counter1).RowDataBound, AddressOf allgridview_rowdatabound
AddHandler Dg(counter1).RowCreated, AddressOf GridView1_RowCreated
ButtonColumn(counter1) = New ButtonField
ButtonColumn(counter1).CommandName = "ViewForm"
ButtonColumn(counter1).ButtonType = ButtonType.Button
ButtonColumn(counter1).HeaderText = "View Form"
ButtonColumn(counter1).Text = "Picture"
Dg(counter1).Columns.Add(ButtonColumn(counter1))
Dg(counter1).DataBind()
Panelbody(counter1).Controls.Add(Dg(counter1))
' Create CollapsiblePanelExtender
cpe(counter1) = New CollapsiblePanelExtender()
cpe(counter1).ID = "cpe" & counter1
cpe(counter1).TargetControlID = Panelbody(counter1).ID
cpe(counter1).ExpandControlID = panelHead(counter1).ID
cpe(counter1).CollapseControlID = panelHead(counter1).ID
cpe(counter1).ScrollContents = False
cpe(counter1).Collapsed = True
cpe(counter1).ExpandDirection = CollapsiblePanelExpandDirection.Vertical
cpe(counter1).SuppressPostBack = True
RecordsFound = True
lblsummary.Dispose()
counter1 += 1
' sqlreadergrid.Close()
End While
Loop While SQLdr.NextResult()
SQLdr.Close()
private sub handles click
Do
While (SQLdr.Read())
counter1 += 1
sqldatagrid.CommandText = "select count(*) from " & SQLdr("type") & " where staff = " & Session("staffid")
recordcounter = sqldatagrid.ExecuteScalar
If recordcounter > 0 Then
' Add Label inside header panel to display text
'Create Body Panel
'set up the datagrids
sqldatagrid.CommandText = SQLdr("sqlcommandtext") & " where staff =" & Session("staffid")
sqlreadergrid = sqldatagrid.ExecuteReader
Dg(counter1).DataSource = sqlreadergrid
Dg(counter1).DataBind()
Me.UpdatePanel1.ContentTemplateContainer.Controls.Add(panelHead(counter1))
Me.UpdatePanel1.ContentTemplateContainer.Controls.Add(Panelbody(counter1))
Me.UpdatePanel1.ContentTemplateContainer.Controls.Add(cpe(counter1))
RecordsFound = True
lblsummary.Dispose()
sqlreadergrid.Close()
End If
End While
Loop While SQLdr.NextResult()
SQLdr.Close()
End If
So basically the staff("sessionid") is picked up from a textbox and then the find button is used to look through various tables and create a dataview for each table in a collapsible panel. As i said this worked fine by only using the find button click event but i needed to add event to it. Now the panel appears and disappears, any further ideas
thanks