Question about DotNetJunkies Hierarchical dg example

Discussion in 'ASP .Net Datagrid Control' started by PedalChick, Aug 7, 2003.

  1. PedalChick

    PedalChick Guest

    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?
     
    PedalChick, Aug 7, 2003
    #1
    1. Advertising

  2. 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



    "PedalChick" <> wrote in message
    news:...
    > I've been trying to customize this code
    >

    http://www.dotnetjunkies.com/Tutorial/ShowContent.aspx?cg=841522C9-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?
     
    Justin Dutoit, Aug 10, 2003
    #2
    1. Advertising

  3. PedalChick

    PedalChick Guest

    "Justin Dutoit" <> wrote in message news:<eqPd#>...
    > 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
     
    PedalChick, Aug 15, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neil Zanella
    Replies:
    2
    Views:
    1,296
    Jonathan Bromley
    Oct 22, 2003
  2. Paddy McCarthy
    Replies:
    3
    Views:
    737
    Anthony J Bybell
    Sep 24, 2004
  3. Davy

    Hierarchical FSM?

    Davy, Apr 1, 2006, in forum: VHDL
    Replies:
    3
    Views:
    1,092
    radarman
    Apr 3, 2006
  4. james

    Hierarchical Datagrid Question

    james, Mar 25, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    144
    james
    Mar 25, 2005
  5. Sam Roberts
    Replies:
    15
    Views:
    315
    Sam Roberts
    Feb 7, 2005
Loading...

Share This Page