Nested Data Lists Problems

Discussion in 'ASP .Net Web Controls' started by Roberto Modica, Dec 1, 2003.

  1. Hi, i have a nested data list which is supposed to expand
    a list of categories. e.g.

    --Initial Set Of Categories
    HOME
    CAT A
    CAT B
    CAT C

    --After CAT A Click
    HOME
    CAT A
    - SUB CAT A
    - SUB CAT B
    CAT C
    CAT D

    I can get to this stage, although i do have to click the
    links twice which is very strage (Any Ideas??) The next
    stage is where i get problems:

    --After SUB CAT A Click
    HOME
    CAT A
    - SUB CAT A
    - - - Sub Sub Cat A
    - - - Sub Sub Cat B
    - SUB CAT B
    CAT C
    CAT D

    For some reason when i click on the first level expanded
    list nothing happens, i do not get any errors, just
    nothing happens. here is my code:

    --default.aspx

    <%@ page inherits="WebMenu" src="codebehind.vb"
    AutoEventWireup="false"%>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    </head>
    <body>
    <form runat="server">
    <ASP:DataList DataKeyField="ID" id="grdCategories"
    runat="server">
    <ItemTemplate>
    <asp:linkbutton id="selCategoryID" Text='<%
    #DataBinder.Eval(Container.DataItem, "SiteCategoryName") %
    >' CommandName="Select" class="SubHead" runat="server"/>

    </ItemTemplate>
    <SelectedItemTemplate>
    <asp:linkbutton id="selCategoryID"
    Text='<%#DataBinder.Eval
    (Container.DataItem, "SiteCategoryName") %>'
    CommandName="Select" class="SubHead" runat="server"/>
    <ASP:DataList id="grdSubCat1"
    DatKeyField="ID" runat="server" datasource= '<%
    #Container.DataItem.CreateChildView("myrel") %>' >
    <ItemTemplate>
    <asp:linkbutton id="subcat1"
    Text='<%# Container.DataItem("SiteCategoryName") %>'
    CommandName="Select" class="SubHead" runat="server"/>
    </ItemTemplate>
    <SelectedItemTemplate>
    <asp:linkbutton
    id="subcat1" Text='<%# Container.DataItem
    ("SiteCategoryName") %>' CommandName="Select"
    class="SubHead" runat="server"/>
    <ASP:DataList
    id="grdSubCat2" runat="server" DataKeyField="ID"
    datasource= '<%# Container.DataItem.CreateChildView
    ("myRel") %>' >
    <ItemTemplate>

    <asp:linkbutton id="subcat2" Text='<%#
    Container.DataItem("SiteCategoryName") %>'
    CommandName="Select" class="SubHead" runat="server"/>
    </ItemTemplate>
    </ASP:DataList>
    </SelectedItemTemplate>
    </ASP:DataList>
    </SelectedItemTemplate>
    </ASP:DataList>
    </form>
    </body>
    </html>

    -_Codebehind.vb

    'Import Required Name Spaces
    Imports System
    Imports System.Data
    Imports System.Data.SQLClient
    Imports System.Web.UI.WebControls
    Imports System.Web.UI

    Public Class WebMenu
    Inherits Page

    'Declare Class Variables
    'Dim CategoryID As Integer
    Dim ParentID As Integer
    Dim SubParentID As Integer

    'Declare Corrosponding Page Elements **REQUIRED**
    Dim Protected WithEvents grdCategories As DataList
    Dim Protected WithEvents grdSubCat1 As DataList
    Dim Protected WithEvents grdSubCat2 As DataList
    Dim Protected WithEvents grdSubCat3 As DataList

    Private Sub Page_Load(byVal sender As Object,
    byVal e as EventArgs) Handles MyBase.Load

    'IF NOT isPostback THEN
    'Bind The Data List
    'BindDataList()

    'END IF

    'Declare Connection Vars
    Dim MyConn As String
    = "server=WIN2KSERVER;uid=sa;pwd=;database=ENUTZDEV"
    Dim MyConnection As New SqlConnection
    (MyConn)

    'Declare SQL Statment Vars
    Dim SQL As String
    Dim SQL1 As String
    Dim SQL2 As String

    'Create SQL Adapters
    Dim cmd As SqlDataAdapter
    Dim cmd1 As SqlDataAdapter
    Dim cmd2 As SqlDataAdapter

    'Declare Dataset to store our related
    tables
    Dim ds As DataSet = New DataSet

    'Set First SQL Statement And Fill DataSet
    SQL = "SELECT * FROM tblSiteCategories
    WHERE SiteCategoryParent = 0"
    cmd = New SqlDataAdapter(SQL,
    MyConnection)
    cmd.Fill(ds, "MainCat")

    'Set Second SQL Statement And Fill DataSet
    SQL1 = "SELECT * FROM tblSiteCategories
    WHERE SiteCategoryLevel = 1"
    cmd1 = New SqlDataAdapter(SQL1,
    MyConnection)
    cmd1.Fill(ds, "FirstLevel")

    'Set Third And Final SQL Statement And
    Fill DataSet
    SQL2 = "SELECT * FROM tblSiteCategories
    WHERE SiteCategoryLevel = 2"
    cmd2 = New SqlDataAdapter(SQL2,
    MyConnection)
    cmd2.Fill(ds, "SecondLevel")

    'Create Relationships
    ds.Relations.Add("myRel", ds.Tables
    ("MainCat").Columns("ID"), ds.Tables("FirstLevel").Columns
    ("SiteCategoryParent"))
    ds.Relations.Add("myChildRel", ds.Tables
    ("FirstLevel").Columns("ID"), ds.Tables
    ("SecondLevel").Columns("SiteCategoryParent"))

    'Bind Data
    grdCategories.Datasource=ds.Tables
    ("MainCat").DefaultView
    DataBind()

    End Sub



    End Class

    I am new to ASP.NET so go easy on me.

    Thank you

    Roberto
    Roberto Modica, Dec 1, 2003
    #1
    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. JustSomeGuy

    Sorting lists of lists...

    JustSomeGuy, Jun 17, 2004, in forum: C++
    Replies:
    0
    Views:
    305
    JustSomeGuy
    Jun 17, 2004
  2. Jon Slaughter

    lists of lists

    Jon Slaughter, Dec 13, 2004, in forum: C++
    Replies:
    4
    Views:
    404
    Buster
    Dec 13, 2004
  3. Charlotte Henkle

    Counter for items in lists in lists?

    Charlotte Henkle, Sep 25, 2004, in forum: Python
    Replies:
    8
    Views:
    388
    Charlotte Henkle
    Sep 26, 2004
  4. robin
    Replies:
    10
    Views:
    530
    Dave Hansen
    Apr 12, 2006
  5. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    384
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
Loading...

Share This Page