Question about DotNetJunkies Hierarchical dg example

P

PedalChick

I've been trying to customize this code
http://www.dotnetjunkies.com/Tutori...22C9-FFBD-4C57-BD48-F62B55057FF3&forumID=4117
to suit my own needs. I can get the hierarchical display using this
method - it's pretty cool! But I have one problem that screws up the
entire +/- show/hide concept.
Here's the deal - I am getting my data from an Access db rather that
SQL used in their example.
When trying to track down why exactly nothing regarding the +/-
functions worked, I discovered this strangeness: although the empty
cells (left in the detail rows, right in the master rows) appear empty
on the screen, and if you try and highlight them you get a single
space highlighted, all of the If statements that depend on the text =
" " (eg. dgValues.Items(icount).Cells(1).Text = " ") never work.

Is there another way to create this If statement? I tried using
Len(dgValues.Items(iCount).Cells(1).Text) < 1, = 1, > 1 - this never
worked because for some reason, the length of the string in the empty
cells was always 6 is the cell was empty.
WTF?
If the cell contains data, the len() calculation is correct.

Please help!!!
What is in that cell that I cannot see?
 
J

Justin Dutoit

It could be &nbsp; Downlevel browsers like Netscape 4 (@$**!!) won't
render the table cell unless there is an &nbsp; in it (non-breaking space).

hth
Justin Dutoit
 
P

PedalChick

Justin Dutoit said:
It could be &nbsp; Downlevel browsers like Netscape 4 (@$**!!) won't
render the table cell unless there is an &nbsp; 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. "&nbsp;" 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 <> "&nbsp;" 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 =
"&nbsp;"
If MyDataGrid.Items(iCount).Cells(4).Text <>
"&nbsp;" 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 =
"&nbsp;" 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 =
"&nbsp;" 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 =
"&nbsp;" 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 =
"&nbsp;" And MyDataGrid.Items(iCount).Cells(1).Text = "&nbsp;"
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 =
"&nbsp;"
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 =
"&nbsp;"
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 <>
"&nbsp;" 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 =
"&nbsp;"
If MyDataGrid.Items(iCount).Cells(4).Text <>
"&nbsp;" 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 = "&nbsp;" and
MyDataGrid.Items(iCount).Cells(4).Text <> "&nbsp;" 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 =
"&nbsp;"
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 = "&nbsp;" And
MyDataGrid.Items(iCount).Cells(1).Text = "&nbsp;"
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top