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
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
<%--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>