通过具有相同ID的querystring传递多个值 [英] passing more then one value with the querystring with the same id

查看:73
本文介绍了通过具有相同ID的querystring传递多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据列表,我想列出来自查询字符串的产品.它的工作方式如下: Default.aspx/?ProductID = 1 我得到了1种想要的产品.但是我想添加更多像这样的产品 Default.aspx/?ProductID = 1,15,25 并退回三款产品.我该如何运作?

I have a datalist that I want to list the Products that are comming from the Querystring. It works like this: Default.aspx/?ProductID=1 I get 1 product like I want. But I want to add more products like this Default.aspx/?ProductID=1,15,25 and get three products back. How do I make that to work?

<asp:DataList ID="DataList1" runat="server">
    <ItemStyle VerticalAlign="Top" />
    <ItemTemplate>
        <a href="../Product/Default.aspx?ProductID=<%#Eval("ProductID") %>">
            <asp:Label ID="lblName" runat="server" Text='<%#Eval("Name") %>' />
            <asp:Label ID="lblPrice" runat="server" Text='<%#Eval("Price") %>' />
        </a>
    </ItemTemplate>
</asp:DataList>


  protected void Page_Load(object sender, EventArgs e)
{
    string id = Request.QueryString["ProductID"];

    DataTable table = CategoryAccess.GetList(id);

    list.DataSource = table;
    list.DataBind();     
}


ALTER PROCEDURE GetList
@ProductID INT

AS
SELECT ProductID, Name, Price 
FROM Product
WHERE (ProductID = @ProductID)

推荐答案

您可以:

/page.aspx?ProductID=1&ProductID=15&ProductID=25

然后 Request.Querystring("ProductID")将返回 1,15,25

然后可以将其放入 ArrayList ,例如 Request.Querystring("ProductID").split(,")

This can then be put into an ArrayList like Request.Querystring("ProductID").split(",")

虽然将这3个值作为参数传递比较棘手,但您最好将其作为xml传递:

Passing those 3 values as a parameter is a bit more tricky though, youre probably best passing it as xml:

为一个SQL参数传递多个值

这篇关于通过具有相同ID的querystring传递多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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