Click here to Skip to main content
15,029,162 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
sir please provide me code when how to bind from database

html code are

XML
<div id='cssmenu'>
<ul>
   <li><a href="Default.aspx"><span>Home</span></a></li>
   <li class='active has-sub'><a href="products.htm"><span>Women</span></a>
      <ul>
        <li class='has-sub'><a href="products.htm"><span>Top</span></a></li>
         <li class='has-sub'><a href="products.htm"><span>Shirt</span></a></li>
         <li class='has-sub'><a href="products.htm"><span>Jeans</span></a></li>
         <li class='has-sub'><a href="products.htm"><span>Suit</span></a></li>

      </ul>
   </li>
   <li><a href="products.htm"><span>Men</span></a>
   <ul>
         <li class='has-sub'><a href="products.htm"><span>T-Shirt</span></a></li>
         <li class='has-sub'><a href="products.htm"><span>Shirt</span></a></li>
         <li class='has-sub'><a href="products.htm"><span>Jeans</span></a></li>
         <li class='has-sub'><a href="products.htm"><span>Formal Shirt</span></a></li>

      </ul>
   </li>
   <li class='last'><a href='#'><span>Sale</span></a></li>
   <li><a href='#'><span>Handicrafts</span></a></li>
      <li><a href="blog.htm"><span>Blog</span></a></li>
       <li><a href="contact.htm"><span>Contact</span></a></li>
   </li>
</ul>
</div>


additional information copied from comments below
this is category table
SQL
CREATE TABLE [dbo].[tblcategory](
[Id] [int] IDENTITY(1,1) NOT NULL,
[category] [nvarchar](max) NULL,
[cat_image] [nvarchar](max) NULL,
[descri] [nvarchar](max) NULL,
[applydate] [nvarchar](50) NULL,
CONSTRAINT [PK_tblcategory] PRIMARY KEY CLUSTERED 
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO


this is subcategory table
SQL
CREATE TABLE [dbo].[tblproduct](
[Id] [int] IDENTITY(1,1) NOT NULL,
[cat_id] [int] NULL,
[product_name] [nvarchar](50) NULL,
[product_image] [nvarchar](max) NULL,
[descri] [nvarchar](max) NULL,
[applydate] [nvarchar](50) NULL,
CONSTRAINT [PK_tblproduct] PRIMARY KEY CLUSTERED 
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO


i want to create category like menu & subcategory like submenu dynamicly
Posted
Updated 30-Aug-14 3:48am
v3
Comments
David Lee 145 30-Aug-14 8:24am
   
What kind of database do you use ?
Do you have table schema?
[no name] 30-Aug-14 8:44am
   
yes sir
[no name] 30-Aug-14 8:45am
   
this is category table


CREATE TABLE [dbo].[tblcategory](
[Id] [int] IDENTITY(1,1) NOT NULL,
[category] [nvarchar](max) NULL,
[cat_image] [nvarchar](max) NULL,
[descri] [nvarchar](max) NULL,
[applydate] [nvarchar](50) NULL,
CONSTRAINT [PK_tblcategory] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
[no name] 30-Aug-14 8:46am
   
this is subcategory table

CREATE TABLE [dbo].[tblproduct](
[Id] [int] IDENTITY(1,1) NOT NULL,
[cat_id] [int] NULL,
[product_name] [nvarchar](50) NULL,
[product_image] [nvarchar](max) NULL,
[descri] [nvarchar](max) NULL,
[applydate] [nvarchar](50) NULL,
CONSTRAINT [PK_tblproduct] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
[no name] 30-Aug-14 8:47am
   
i want to create category like menu & subcategory like submenu dynamicly

1. Write your query.
- JOIN your two table.

2. Get the data from database.
C#
string queryString = "your query is here";
DataSet dataset = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(
queryString, connection);        
adapter.Fill(dataset);


3. Render your html UI.
Do you use asp.net webform or mvc? I don't know what you exactly want.
Here is the msdn sample. You only need to replace the template.

http://msdn.microsoft.com/ko-kr/library/system.web.ui.webcontrols.repeater(v=vs.110).aspx[^]

4. Make dropdown menu.
Use bootstrap or other libraries. You can make it very easily.
Here is the sample of bootstrap.

http://getbootstrap.com/components/#dropdowns[^]
   
v3
the best way to bind the data using datatable

and add datalist1 table within datalist2
bind second datalist at onitemcreated in datalist1



XML
<asp:DataList ID="DataList1" runat="server" OnItemCreated="DataList1_ItemCreated">

<ItemTemplate>
                <%# Eval("main_cate") %>
                                <asp:DataList ID="DataList2" runat="server">

                                        <ItemTemplate>
                                            <div class="sub_cate"style="margin-left: 20px">
                            <%# Eval("sub_cate") %>
                                            </div>

                                        </ItemTemplate>

                                 </asp:DataList>
</ItemTemplate>

</asp:DataList>




onitemcreated method write fatching record for datalist2 with where condition
   
Comments
[no name] 1-Sep-14 7:24am
   
sir thanks
[no name] 1-Sep-14 7:28am
   
sir please provide me item created cs code

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