Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Dear All,

I am generating the TreeView by the following code:

XML
<ul id="navigation" class="treeview">

            <asp:Repeater runat="server" ID="repeatGroups">
                <ItemTemplate>
                    <li><a href='Default.aspx?name=<%# Eval("GroupName") %>'><%# Eval("GroupName")%></a>

                        <asp:Repeater runat="server" ID="repeatCategory" DataSource='<%# Eval("Categories")%>' OnItemDataBound="repeatCategory_ItemDataBound">
                            <HeaderTemplate><ul></HeaderTemplate>
                            <ItemTemplate>
                                <li><a href='Default.aspx?name=<%# Eval("Name") %>'><%# Eval("Name") %></a>

                                    <asp:Repeater runat="server" ID="repeatItem" DataSource='<%# Eval("Items")%>'>
                                        <HeaderTemplate><ul></HeaderTemplate>
                                        <ItemTemplate>
                                            <li><a href='Default.aspx?name=<%# Eval("Name") %>'><%# Eval("Name")%></a></li>
                                        </ItemTemplate>
                                        <FooterTemplate></ul></FooterTemplate>
                                    </asp:Repeater>

                                </li>
                            </ItemTemplate>
                            <FooterTemplate></ul></FooterTemplate>
                        </asp:Repeater>

                    </li>
                </ItemTemplate>
            </asp:Repeater>

        </ul>


.cs code:
C#
protected void repeatCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
       {
           if (e.Item.DataItem != null)
           {
               //bind any products
               Repeater repeatItem = (Repeater)e.Item.FindControl("repeatItem");
               if (repeatItem != null)
                   repeatItem.Visible = (repeatItem.Items.Count > 0) ? true : false;

           }
       }



With the above code, I can display a Treeview by hardcoding the items into the Treeview using ArrayList. But, I want to access the items from the database(SQL Server) and display the same.

Can Any one suggest me how should be the structure of the table in my database?

Thanks & Regards
Posted

One of the points of tiered application design is that the UI shouldn't care how the backend data is stored, your middle tier is reponsible for transforming the data into whatever format is required.

Your database should be designed so that logical entities are grouped in normalised tables not how it should be displayed to an end user.

Find a database design that fits the data and then transform it so that it can be presented to a user in your business logic tier.

Im my experience data models change less often than UI's as when more features are added at the front end they often don't require changes to the table structures - it is jsut cutting the data differently.
 
Share this answer
 
Hi raj,

Creating Treeview[^]
 
Share this answer
 
Hi try with this,

  TreeNode pnode, cnode, dnode;
TreeNode pnode, cnode, dnode;
    view.Nodes.Clear();



   DataSet ds =sh.GetDataSet("SELECT   distinct  Table1.value1,Table1.value2 FROM         table2 INNER JOIN    Table1 ON table2.Section = Table1.value1");


   foreach(DataRow dr in ds.Tables[0].Rows)
   {

       pnode = new TreeNode();
       pnode.Text = dr["value2"].ToString();
       pnode.Value = dr["value1"].ToString();
       view.Nodes.Add(pnode);

       view.CollapseAll();


       DataSet ds1 = sh.GetDataSet("SELECT    distinct table2.SubSection FROM table2 INNER JOIN    Table1 ON table2.Section = Table1.value1  where Table1.value2 like '" + dr["value2"].ToString() + "'  ");
           foreach (DataRow dr1 in ds1.Tables[0].Rows)
           {

               cnode = new TreeNode();
               cnode.Text = dr1["SubSection"].ToString();
                 pnode.ChildNodes.Add(cnode);


               DataSet ds2 = sh.GetDataSet("SELECT    distinct  table2.value4,table2.value3  FROM         table2 INNER JOIN    Table1 ON table2.Section = Table1.value1  where Table1.value2 like '" + dr["value2"].ToString() + "' and table2.SubSection like '" + dr1["SubSection"].ToString() + "' ");
               foreach (DataRow dr2 in ds2.Tables[0].Rows)
               {


                   dnode = new TreeNode();
                   dnode.Text = dr2["value3"].ToString();
                   dnode.Value = dr2["value4"].ToString();
                   cnode.ChildNodes.Add(dnode);

               }
           }


regards,
Pal
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900