Click here to Skip to main content
11,709,120 members (59,627 online)
Rate this: bad
Please Sign up or sign in to vote.

I have a page which contains list of Products displayed based on catagories...

When i select catagory in left side menu i have displayed the products based on that selected catagory but in the url the catagiry id has not been changed.i need to change the catagory id in the url of that page...

The design code looks like this....

<asp:DataList runat="server" OnItemDataBound="dlProducts_ItemDataBound" ID="dlProducts"
                               RepeatColumns="4" RepeatDirection="Horizontal">
                                       <asp:HiddenField runat="server" ID="hdnItemID" Value='<%# DataBinder.Eval(Container.DataItem, "ItemID")%>' />
                                       <asp:HiddenField ID="hdndCatlog" runat="server" />
                                       <div class="productsimg"  önclick="SelectProduct(<%# DataBinder.Eval(Container.DataItem, "ItemID")%>,this);">
                                           <img src='<%#((string[]) DataBinder.Eval(Container.DataItem, "ThumbnailPaths"))[0]%>' />
                                       <div class="productscost">
                                           <div class="productsname">
                                                   <%# DataBinder.Eval(Container.DataItem, "StockNo")%></h6>
                                                   $<asp:Label runat="server" ID="lblItemPrice"></asp:Label></p>
                                           <a href='java<!-- no -->script:AddItemtoCart(<%# DataBinder.Eval(Container.DataItem, "ItemID")%>)'>
                                               <div class="addtocart">
                                                   Add to CART

When i click cataory name in this i have displayed products(items) ..code look like this..

protected void dlCategories_ItemCommand(object sender, DataListCommandEventArgs e)
          if (e.CommandName == "SELECT")
              CtlId = int.Parse(e.CommandArgument.ToString());
              Session["CtlId"] = CtlId;

Url like this .....


when i click another catagory the catagory id has not changing in the above url..

Please help me on this issue..

Posted 22-Mar-13 6:52am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try this. it works good Smile | :)

aspx page
       <div style="padding:10px; width: 200px; height:500px; background-color:#2C956C; float: left">
           <asp:label id="Label1" runat="server" text="Categories" font-bold="True" xmlns:asp="#unknown">
               Font-Size="16pt" Font-Underline="True" ForeColor="White"></asp:label>
           <asp:dropdownlist id="DropDownListCategories" runat="server" xmlns:asp="#unknown">
               AutoPostBack="True" Height="30px"
       <div style="width: 800px; height:499px; padding:10px; background-color: #BEAA6C; float: left">
           <asp:gridview id="ProductOfCategory" runat="server" backcolor="White" xmlns:asp="#unknown">
               BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
               ForeColor="Black" GridLines="Horizontal">
               <footerstyle backcolor="#CCCC99" forecolor="Black" />
               <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
               <pagerstyle backcolor="White" forecolor="Black" horizontalalign="Right" />
               <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
               <sortedascendingcellstyle backcolor="#F7F7F7" />
               <sortedascendingheaderstyle backcolor="#4B4B4B" />
               <sorteddescendingcellstyle backcolor="#E5E5E5" />
               <sorteddescendingheaderstyle backcolor="#242121" />

protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)
                int ID = 0;
                int.TryParse(Request.QueryString["categoryID"], out ID);
                if (ID > 0)
        private void GetProdutByCategory(int CategoryID)
            SqlDataAdapter da = new SqlDataAdapter("Select ProductName,UnitPrice,UnitsInStock from Products Where CategoryID=@id", "Server=.;Database=NorthWind;uid=sa;pwd=1");
            da.SelectCommand.Parameters.AddWithValue("@id", CategoryID);
            DataTable dt = new DataTable();
            ProductOfCategory.DataSource = dt;
        private void GetCategories()
            SqlDataAdapter da = new SqlDataAdapter("Select * from Categories", "Server=.;Database=NorthWind;uid=sa;pwd=1");
            DataTable dt = new DataTable();
            DropDownListCategories.DataSource = dt;
            DropDownListCategories.DataTextField = "CategoryName";
            DropDownListCategories.DataValueField = "CategoryID";
        protected void DropDownListCategories_SelectedIndexChanged(object sender, EventArgs e)
            if (DropDownListCategories.SelectedIndex != -1)
                Response.Redirect("WebForm2.aspx?categoryID=" + DropDownListCategories.SelectedValue);

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 580
1 Maciej Los 235
2 Peter Leow 219
3 OriginalGriff 214
4 Mika Wendelius 170
0 OriginalGriff 9,348
1 Sergey Alexandrovich Kryukov 8,727
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100