当我在同一页面中选择不同的项目时,如何更改页面URL [英] How to change page url when i select different item in the same page

查看:67
本文介绍了当我在同一页面中选择不同的项目时,如何更改页面URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个页面,其中包含根据类别显示的产品列表...



当我在左侧菜单中选择类别时,我已根据所选类别显示产品但在网址中catagiry id尚未更改。我需要更改该页面网址中的类别ID ...



设计代码如下所示....





Hi,

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">
                               <ItemTemplate>
                                   <li>
                                       <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>
                                       <div class="productscost">
                                           <div class="productsname">
                                               <h6>
                                                   <%# DataBinder.Eval(Container.DataItem, "StockNo")%></h6>
                                               <p>
                                                   $<asp:Label runat="server" ID="lblItemPrice"></asp:Label></p>
                                           </div>
                                           <a href=''java<!-- no -->script:AddItemtoCart(<%# DataBinder.Eval(Container.DataItem, "ItemID")%>)''>
                                               <div class="addtocart">
                                                   Add to CART
                                               </div>
                                           </a>
                                       </div>
                                   </li>
                               </ItemTemplate>
                           </asp:DataList>









当我点击此中的cataory名称我展示了产品(项目)..代码看起来像这样..














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;
              BindItems(CtlId);
          }
      }





这样的网址.....



http:// localhost:58698 / Products / 37 [ ^ ]





当我点击另一个类别时,catagory id在上面的网址中没有变化..



请帮我解决这个问题..



谢谢。



Url like this .....

http://localhost:58698/Products/37[^]


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

Please help me on this issue..

Thanks.

推荐答案

< asp:Label runat =serverID =lblItemPrice>< / ASP:标签>< / p为H.
< / div>
< a href =''java<! - no - >脚本:AddItemtoCart(<%#DataBinder.Eval(Container.DataItem,ItemID)%>)''>
< div class =addtocart>
加入购物车
< / div>
< / a>
< / div>
< / li>
< / ItemTemplate>
< / asp:DataList>
<asp:Label runat="server" ID="lblItemPrice"></asp:Label></p> </div> <a href=''java<!-- no -->script:AddItemtoCart(<%# DataBinder.Eval(Container.DataItem, "ItemID")%>)''> <div class="addtocart"> Add to CART </div> </a> </div> </li> </ItemTemplate> </asp:DataList>









当我点击此中的cataory名称我展示了产品(项目)..代码看起来像这样..














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;
              BindItems(CtlId);
          }
      }





这样的网址.....



http:// localhost:58698 / Products / 37 [ ^ ]





当我点击另一个类别时,catagory id在上面的网址中没有变化..



请帮我解决这个问题..



谢谢。



Url like this .....

http://localhost:58698/Products/37[^]


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

Please help me on this issue..

Thanks.


试试这个。它工作得很好:)



aspx页面

Try this. it works good :)

aspx page
<div>
       <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>
           <br />
           <asp:dropdownlist id="DropDownListCategories" runat="server" xmlns:asp="#unknown">
               AutoPostBack="True" Height="30px"
               onselectedindexchanged="DropDownListCategories_SelectedIndexChanged"
               Width="100%">
           </asp:dropdownlist>
       </div>
       <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" />
           </asp:gridview>
       </div>
   </div>





CodeBehind



CodeBehind

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetCategories();
                
                int ID = 0;
                int.TryParse(Request.QueryString["categoryID"], out ID);
                if (ID > 0)
                {
                     GetProdutByCategory(ID);
                }
            }
        }

        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();
            da.Fill(dt);
            ProductOfCategory.DataSource = dt;
            ProductOfCategory.DataBind();
        }

        private void GetCategories()
        {
            SqlDataAdapter da = new SqlDataAdapter("Select * from Categories", "Server=.;Database=NorthWind;uid=sa;pwd=1");
            DataTable dt = new DataTable();
            da.Fill(dt);
            DropDownListCategories.DataSource = dt;
            DropDownListCategories.DataTextField = "CategoryName";
            DropDownListCategories.DataValueField = "CategoryID";
            DropDownListCategories.DataBind();

           
        }

        protected void DropDownListCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownListCategories.SelectedIndex != -1)
            {
                Response.Redirect("WebForm2.aspx?categoryID=" + DropDownListCategories.SelectedValue);
            }
        }


这篇关于当我在同一页面中选择不同的项目时,如何更改页面URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆