Click here to Skip to main content
16,006,605 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello i developed static menu from menucool website but in my website i have to develop dynamic menu so please help me

My table

MainCategory_Master:

MainCategory_ID int Unchecked
MainCategory_Name nvarchar(50) Checked

and

SubCategory_Master:

SubCategory_ID int Unchecked
SubCategory_Name nvarchar(50) Checked
MainCategory_ID int Unchecked


and code for static menu

XML
<!DOCTYPE html>
<html>
<head>
    <title>Menucool Drop Down Menu</title>
    <link href="Styles/ddmenu.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/ddmenu.js" type="text/javascript"></script>
</head>
<body>
<nav id="ddmenu">
    <ul>

    <li><a href="Home.aspx">Home</a>
    </li>
        <li><a href="#">MEN</a>
            <div>
                <div class="column">
                    <b>MEN'S CLOTHING</b>
                    <a href="DisplayAll.aspx?type=T Shirts">T-SHIRTS</a>
                    <a href="DisplayAll.aspx?type=Casual Shirts"> CASUAL SHIRTS</a>
                    <a href="DisplayAll.aspx?type=Formal Shirts"> FORMAL SHIRTS</a>
                    <a href="DisplayAll.aspx?type=Sweaters and Sweatshirts">SWEATERS and SWEATSHIRTS</a>
                    <a href="DisplayAll.aspx?type=Jackets and Blazers">JACKETS and BLAZER</a>
                    <a href="DisplayAll.aspx?type=Kurtas">KURTAS</a>
                    <a href="DisplayAll.aspx?type=Jeans">JEANS</a>
                    <a href="DisplayAll.aspx?type=Shorts">Shorts</a>
                    <a href="DisplayAll.aspx?type=Trousers">TROUSERS</a>


                </div>


                <div class="column" style="width:200px;text-align:center;">
                    <img src="Images/img1.jpg" alt="Image" style="width:200px; height:175px;" />

                </div>
            </div>
     </li>


<li><a href="#">WOMEN</a>
            <div>
                <div class="column">
                    <b>WOMEN'S CLOTHING</b>
                    <a href="DisplayAll.aspx?type=Sarees">SAREES</a>
                    <a href="DisplayAll.aspx?type=Dresses">DRESSES</a>
                    <a href="DisplayAll.aspx?type=Shrugs and Jackets">Shrugs and JACKETS</a>
                    <a href="DisplayAll.aspx?type=Sweaters and Sweatshirts">SWEATERS and SWEATSHIRTS</a>
                    <a href="DisplayAll.aspx?type=Jeans and Jeggings">Jeans and Jeggings</a>
                    <a href="DisplayAll.aspx?type=Shorts and Skirts">SHORTS and SKIRTS</a>
                    <a href="DisplayAll.aspx?type=Leggings and Capris">LEGGINGS and CAPRIS</a>
                    <a href="DisplayAll.aspx?type=Trousers">TROUSERS</a>
                    <a href="DisplayAll.aspx?type=Polos and T-Shirts">POLOS and T-SHIRTS</a>
            </div>


                <div class="column" style="width:200px;text-align:center;">
                    <img src="Images/img2.jpg" alt="Image" style="width:200px; height:175px;" />

                </div>
            </div>
     </li>


<li><a href="#">KIDS</a>
            <div>
                <div class="column">
                    <b>FOR BOYS</b>
                    <a href="DisplayAll.aspx?type=Boys Top Wear">TOP WEAR</a>
                    <a href="DisplayAll.aspx?type=Boys Ethnic Wear">ETHNIC WEAR</a>
                    <a href="DisplayAll.aspx?type=Boys Winter Wear">WINTER WEAR</a>
                    <a href="DisplayAll.aspx?type=Boys Bottom Wear">BOTTOM WEAR</a>
                    <a href="DisplayAll.aspx?type=Boys Night Wear">NIGHT WEAR</a>
                    <a href="DisplayAll.aspx?type=Boys Sets">SETS</a>
            </div>


                <div class="column">
                    <b>FOR GIRS</b>
                    <a href="DisplayAll.aspx?type=Girls Top Wear">TOP WEAR</a>
                    <a href="DisplayAll.aspx?type=Girls Ethnic Wear">ETHNIC WEAR</a>
                    <a href="DisplayAll.aspx?type=Girls Winter Wear">WINTER WEAR</a>
                    <a href="DisplayAll.aspx?type=Girls Bottom Wear">BOTTOM WEAR</a>
                    <a href="DisplayAll.aspx?type=Girls Night Wear">NIGHT WEAR</a>
                    <a href="DisplayAll.aspx?type=Girls Sets">SETS</a>
            </div>


                <div class="column" style="width:200px;text-align:center;">
                    <img src="Images/img.jpg" alt="Image" style="width:200px; height:175px;"  />

                </div>
            </div>
     </li>

     <li><a href="#">NEW ARRIVALS</a>
            <div>
                <div class="column">
                    <a href="#"><b>MEN</b></a>
                </div>


                <div class="column">
                    <a href="#"><b>WOMEN</b></a>
                </div>


                <div class="column" style="width:200px;text-align:center;">
                    <img src="Images/img3.jpg" alt="Image" style="width:200px; height:175px;" />

                </div>
                 <div class="column" style="width:200px;text-align:center;">
                    <img src="Images/img4.jpg" alt="Image" style="width:200px; height:175px;" />

                </div>
            </div>
     </li>
</body>
</html>


now how i develop dynamic menu please help by code
Posted
Comments
Please try to do something by your own. And if you face any difficulty, then come back here with the code.
The members will be happy to help you then.

Hints
Fetch the data from DataBase table, build your dynamic menu bu StringBuilder Class and then append that to the div which you want to.
Member 9815058 8-May-13 6:05am    
Thanks For Hints ... and ya i try
Most Welcome.... Please let me know after you implement, otherwise I will help you if any problem.

Thanks,
Tadit
Member 9815058 8-May-13 6:26am    
I started and if face any problem then tell you..
Ok... Click reply button when you want to reply to me, don't add by clicking on "Have a question or Comment" as you did now.
I will not be notified.. Got it ?

1 solution

SQL
Table : MainCategory_Master

MainCategory_ID	        int	        Unchecked
MainCategory_Name	nvarchar(50)	Checked

Table : SubCategory_Master

SubCategory_ID	        int	        Unchecked
SubCategory_Name	nvarchar(50)	Checked
MainCategory_ID	        int	        Unchecked


In CS file and Page_Load event write following code

C#
con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Online Shopping Portal.mdf;Integrated Security=True;User Instance=True");
con.Open();
string select="SELECT MainCategory_Master.MainCategory_Name,SubCategory_Master.SubCategory_Name,MainCategory_Master.MainCategory_ID FROM MainCategory_Master INNER JOIN SubCategory_Master ON MainCategory_Master.MainCategory_ID = SubCategory_Master.MainCategory_ID";
cmd = new SqlCommand(select, con);
dr = cmd.ExecuteReader();
String mcat = "";
String menu = "<nav id='ddmenu'><ul id='mainUL'>";
while (dr.Read())
{
  if (mcat == "")
  {
      menu += "<li><a href='#'>" + dr[0].ToString() + "</a><div><div class='column'><b>" + dr[0].ToString() + "'s clothing</b>";
      mcat = dr[0].ToString();
  }
  else if (mcat != dr[0].ToString() && menu != "<ul id='mainUL'>")
  {
      menu += "</div></div></li><li><A href='#'>" + dr[0].ToString() + "</a><div><div class='column'><b>"+dr[0].ToString()+"'s clothing</b>";
      mcat = dr[0].ToString();
  }
  menu += "<A href='DisplayAll.aspx?SubCategory_Name="+dr[1].ToString()+"'>" + dr[1].ToString() + "</a>";

}
menu += "</ul>";
Response.Write("<div class='ddmenu'>'" + menu + "'</div>");


and DisplayAll.aspx file
XML
<%--DataList For Display Items--%>

    <div id="displayproduct" class="c2">
    <asp:DataList
         ID="dlMenu"
         runat="server"
         DataSourceID="srcMenu"
         RepeatColumns="4" >

        <ItemTemplate>

            <asp:HyperLink ID="hlDisplay" NavigateUrl='<%#Eval("Product_ID","~/DisplayOne.aspx?Product_ID={0}") %>'  runat="server">

            <asp:Image
                ID="ImgDisplay"
                runat="server"
                ImageUrl='<%#Eval("Product_ID","~/Display.aspx?Product_ID={0}") %>'
                onmouseover="MOver();"
                Width="175" /></asp:HyperLink>
               <br />

            <asp:Label
                ID="lblName"
                runat="server"
                Text='<%#Eval("Item_Name") %>' Font-Size="Smaller" Font-Bold="True" ></asp:Label>
               <br />

            <asp:Label
                ID="lblPriceDis"
                runat="server"
                Text="Rs."></asp:Label>
            <asp:Label
                ID="lblPrice"
                runat="server"
                Text='<%#Eval("Price") %>'></asp:Label>
               <br />

           <asp:Label
             ID="lblAvailableSize"
             runat="server"
             style="visibility:hidden"
             Text='<%#Eval("AvailableSize")%>'></asp:Label>
             <br />

        </ItemTemplate>

     </asp:DataList>
     </div>

    <asp:SqlDataSource ID="srcMenu" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT Product_Master.Product_ID,Item_Master.AvailableSize, Product_Master.Image, Item_Master.Item_Name, Product_Master.Price FROM Product_Master INNER JOIN Item_Master ON Product_Master.Item_ID = Item_Master.Item_ID WHERE (Item_Master.SubCategory_Name =@efg)">
        <SelectParameters>
        <asp:QueryStringParameter Name="efg"  QueryStringField="SubCategory_Name" />
        </SelectParameters>
    </asp:SqlDataSource>
 
Share this answer
 
v2
Comments
My vote of +5 for your dedication and hard-work to solve it by yourself. :)
Keep it up...
Member 9815058 9-May-13 10:23am    
Oh...Thank You So Much For Vote and Ya it is done by your hints so Thanks to you So Much
Thanks... But you did everything... Hats of to you. :)
High five.
Member 9815058 9-May-13 12:39pm    
Thanks U So Much ... Sir
Most welcome... I am young... Please don't call me sir. :P :P

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