C# 在单个变量中存储多个值,并将该变量会话到下一页并转换为字符串

C# 在单个变量中存储多个值,并将该变量会话到下一页并转换为字符串,c#,asp.net,session,C#,Asp.net,Session,这是我的Gridview(很抱歉,没有在stackExchange上上载图像) 当用户单击“添加到购物车”按钮时,将从使用中获得相应的产品id asp html代码:- <asp:Content ID="Content1" ContentPlaceHolderID="main" runat="server" > <asp:GridView ID="GridView3" DataKeyNames="ProductId" OnPageIndexChanging="Gri

这是我的Gridview(很抱歉,没有在stackExchange上上载图像)

当用户单击“添加到购物车”按钮时,将从使用中获得相应的产品id

asp html代码:-

<asp:Content ID="Content1" ContentPlaceHolderID="main" runat="server" >
    <asp:GridView ID="GridView3" DataKeyNames="ProductId"   OnPageIndexChanging="GridView1_PageIndexChanged"  AllowSorting="True" AllowPaging="True" PageSize="5" runat="server" CellPadding="4" EnableModelValidation="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" GridLines="Vertical" PagerStyle-HorizontalAlign="Center" Height="700px" Width="800px" ForeColor="Black" >
        <Columns>
            <asp:BoundField DataField="ProductId" HeaderText="ProductID" />
            <asp:ImageField DataImageUrlField="ProductImage"  HeaderText="ProductImage" AlternateText="Image Not Found"  ControlStyle-Height="150px" ControlStyle-Width="150px"  >
           <ControlStyle Height="150px" Width="150px"></ControlStyle>

              <FooterStyle Height="30px" Width="30px" />
              <ItemStyle BorderStyle="None" BorderWidth="1px" Height="30px" Width="30px" Wrap="False" />
            </asp:ImageField>
            <asp:BoundField DataField="ModelName" HeaderText="ModelName" >
            <ControlStyle Width="30px" />
            </asp:BoundField>
            <asp:BoundField DataField="Brand" HeaderText="Brand" />
            <asp:BoundField DataField="Stock" HeaderText="Stock" />
            <asp:BoundField DataField="Price" HeaderText="Price" />
            <asp:TemplateField HeaderText="Click Button To Buy">
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Add To Cart</asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <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" />
    </asp:GridView>
    <script>
        function myFunction() {
            alert("Please Login\n New User Click SignUp Button on Top");
        }
    </script>
</asp:Content>
我的问题是当用户单击addtocart时 字符串s存储一个productid值,但我需要存储多个productid示例,如
this(9,10,14)
session
将该值存储到shoppingcart的下一页

string s;
protected void LinkButton1_Click(object sender, EventArgs e)
{
    GridViewRow gr = ((sender as LinkButton).NamingContainer as GridViewRow);
    //string s = gr.Cells[0].Text.Trim();
s += gr.Cells[0].Text.Trim() + ";";
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
    GridViewRow gr = ((sender as LinkButton).NamingContainer as GridViewRow);
    string s = gr.Cells[0].Text.Trim();
}
string s;
protected void LinkButton1_Click(object sender, EventArgs e)
{
    GridViewRow gr = ((sender as LinkButton).NamingContainer as GridViewRow);
    //string s = gr.Cells[0].Text.Trim();
s += gr.Cells[0].Text.Trim() + ";";
}