Justin Dutoit said:
It could be Downlevel browsers like Netscape 4 (@$**!!) won't
render the table cell unless there is an in it (non-breaking space).
hth
Justin Dutoit
Thanks! That little note helped get me over my stumbling block and
I've since gotten this cool little widget not only to work correctly,
but have made some improvements. I've added an "expand all" to the
two detail levels and a "collapse all" once they have been expanded.
It turns out the " " vs. " " issue was due to Dreamweaver MX
changing the latter to the former and screwing me up every time I
changed. I have to hand edit in Notepad now...
The grid has three levels, the two expand/collapse buttons are in
cells 0 and 3.
I'll leave out the html...
Imports System
Imports System.Web.UI
Imports System.Web.UI.Webcontrols
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.OracleClient
Public Class NestedTest
Inherits System.Web.UI.Page
Protected WithEvents MyDataGrid As
System.Web.UI.WebControls.DataGrid
Protected WithEvents lblResults As System.Web.UI.WebControls.Label
Protected WithEvents ddlSubmitters as
System.Web.UI.WebControls.Dropdownlist
Protected WithEvents outError As
System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents expBinary as
System.Web.UI.WebControls.LinkButton
Protected WithEvents expQuery as System.Web.UI.WebControls.LinkButton
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
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 PageLoad(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack then
<snip> I start out with a dropdownlist to select data based upon the
submitter and then load the data.</snip>
End If
End Sub
Public Sub ChangeSelectedList(ByVal sender As Object, ByVal objArgs As
System.EventArgs) Handles ddlSubmitters.SelectedIndexChanged
LoadData()
End Sub
Private Sub LoadData()
<snip> fill a dataset with tables and establish relationships. Write
out the data into a new table using the dotnetjunkies example and bind
the table to the datagrid</snip>
MyDataGrid.DataSource = objTable
MyDataGrid.DataBind()
expQuery.visible = true
expBinary.visible = false
SetHierarchical(0)
End Sub
Private Sub SetHierarchical(ByVal bExpanded As Integer)
Dim iCount As Int32
lblResults.Text = MyDataGrid.Items.Count
If bExpanded = 1 Then
For iCount = 0 To MyDataGrid.Items.Count - 1
If MyDataGrid.Items(iCount).Cells(1).Text <> " " Then
CType(MyDataGrid.Items(iCount).Cells(0).Controls(0),
LinkButton).Text = "-"
End If
Next
For iCount = 0 to MyDataGrid.Items.Count - 1
Do While MyDataGrid.Items(iCount).Cells(1).Text =
" "
If MyDataGrid.Items(iCount).Cells(4).Text <>
" " Then MyDataGrid.Items(iCount).Visible = True
iCount += 1
If iCount >= MyDataGrid.Items.Count Then Exit
Do
Loop
expQuery.Text = "Collapse Queries"
Next
Else if bExpanded = 0 Then
For iCount = 0 To MyDataGrid.Items.Count - 1
'hide + on all rows where there is not an
expandable node
If MyDataGrid.Items(iCount).Cells(4).Text =
" " Then
MyDataGrid.Items(iCount).Cells(3).Controls(0).Visible = False
Else
'set the plus sign
CType(MyDataGrid.Items(iCount).Cells(3).Controls(0), LinkButton).Text
= "+"
CType(MyDataGrid.Items(iCount).Cells(3).Controls(0),
LinkButton).CssClass = "secondaryNav"
End If
'hide + on all Query rows where there is not an
expandable node
If MyDataGrid.Items(iCount).Cells(1).Text =
" " Then
MyDataGrid.Items(iCount).Cells(0).Controls(0).Visible = false
Else
'set the plus sign
CType(MyDataGrid.Items(iCount).Cells(0).Controls(0), LinkButton).Text
= "+"
CType(MyDataGrid.Items(iCount).Cells(0).Controls(0),
LinkButton).CssClass = "secondaryNav"
End If
'hide all child nodes and rows of the root nodes
If MyDataGrid.Items(iCount).Cells(1).Text =
" " Then
MyDataGrid.Items(iCount).Visible = False
End If
expQuery.Text = "Expand Queries"
Next
End If
bExpanded = 0
End Sub
Private Sub MyDataGridItemCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
MyDataGrid.ItemCommand
Dim iCount As Int32 = e.Item.ItemIndex + 1
If e.CommandName = "ExpandBinary" Then
If CType(e.Item.Cells(3).Controls(0), LinkButton).Text
= "-" Then
'Hide all child rows in the node careful not to
hide the Query row
Do While MyDataGrid.Items(iCount).Cells(4).Text =
" " And MyDataGrid.Items(iCount).Cells(1).Text = " "
MyDataGrid.Items(iCount).Visible = False
iCount += 1
If iCount >= MyDataGrid.Items.Count Then Exit
Do
Loop
'change the minus to a plus
CType(e.Item.Cells(3).Controls(0),
LinkButton).Text = "+"
Else
'Show all child rows in the node
Do While MyDataGrid.Items(iCount).Cells(4).Text =
" "
MyDataGrid.Items(iCount).Visible = True
iCount += 1
If iCount >= MyDataGrid.Items.Count Then Exit
Do
Loop
'change the plus to a minus
CType(e.Item.Cells(3).Controls(0),
LinkButton).Text = "-"
End If
ElseIf e.CommandName = "ExpandQuery" Then
If CType(e.Item.Cells(0).Controls(0), LinkButton).Text
= "-" and iCount < MyDataGrid.Items.Count Then
'Hide all child rows in the node
Do While MyDataGrid.Items(iCount).Cells(1).Text =
" "
MyDataGrid.Items(iCount).Visible = False
'if this is a binary row set the plus sign as
we are collapsing it too
If MyDataGrid.Items(iCount).Cells(4).Text <>
" " Then CType(MyDataGrid.Items(iCount).Cells(3).Controls(0),
LinkButton).Text = "+"
iCount += 1
If iCount >= MyDataGrid.Items.Count Then Exit
Do
Loop
'hide the total row
'change the minus to a plus
CType(e.Item.Cells(0).Controls(0),
LinkButton).Text = "+"
Else
'Show all Binary rows in the node
If iCount < MyDataGrid.Items.Count Then
Do While MyDataGrid.Items(iCount).Cells(1).Text =
" "
If MyDataGrid.Items(iCount).Cells(4).Text <>
" " Then MyDataGrid.Items(iCount).Visible = True
iCount += 1
If iCount >= MyDataGrid.Items.Count Then Exit
Do
Loop
'change the plus to a minus
CType(e.Item.Cells(0).Controls(0),
LinkButton).Text = "-"
Else if iCount = MyDatagrid.Items.Count Then
If MyDataGrid.Items(iCount).Cells(1).Text = " " and
MyDataGrid.Items(iCount).Cells(4).Text <> " " Then
MyDataGrid.Items(iCount).Visible = True
Else
MyDataGrid.Items(iCount).Visible = False
End If
CType(e.Item.Cells(0).Controls(0), LinkButton).Text = "-"
End If
End If
End Sub
Private Sub ChangeAllQuery(Sender As System.Object, ByVal objArgs As
System.EventArgs) Handles ExpQuery.Click
If expQuery.Text = "Expand Queries" Then
expBinary.visible = true
expBinary.Text = "Expand Binaries"
SetHierarchical(1)
Else
expBinary.visible = false
SetHierarchical(0)
End If
End Sub
Private Sub ChangeAllBinary(Sender As System.Object, ByVal e As
System.EventArgs) Handles ExpBinary.Click
If expBinary.Text = "Expand Binaries"
Dim iCount As Int32
For iCount = 0 To MyDataGrid.Items.Count - 1
'Show all child rows in the node
If CType(MyDataGrid.Items(iCount).Cells(3).Controls(0),
LinkButton).Text = "+"
CType(MyDataGrid.Items(iCount).Cells(3).Controls(0),
LinkButton).Text = "-"
End If
Next
For iCount = 0 To MyDataGrid.Items.Count - 1
Do While MyDataGrid.Items(iCount).Cells(4).Text =
" "
MyDataGrid.Items(iCount).Visible = True
iCount += 1
If iCount >= MyDataGrid.Items.Count Then Exit
Do
Loop
Next
expBinary.Text = "Collapse Binaries"
Else
Dim iCount As Int32
For iCount = 0 To MyDataGrid.Items.Count - 1
If CType(MyDataGrid.Items(iCount).Cells(3).Controls(0),
LinkButton).Text = "-"
CType(MyDataGrid.Items(iCount).Cells(3).Controls(0),
LinkButton).Text = "+"
End If
Next
For iCount = 0 To MyDataGrid.Items.Count - 1
Do While MyDataGrid.Items(iCount).Cells(4).Text = " " And
MyDataGrid.Items(iCount).Cells(1).Text = " "
MyDataGrid.Items(iCount).Visible = False
iCount += 1
If iCount >= MyDataGrid.Items.Count Then Exit
Do
Loop
'change the minus to a plus
Next
expBinary.Text = "Expand Binaries"
End If
End Sub
End Class