1

I have an Update Panel with GridView(databinded). In each row there is a button. If a user clicked a button the a value will be appended to the list. The problem I'm getting is I can only store a value which is last added due to post back. So can someone pls show me the proper way to store it?

ASPX:

 <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
        <ContentTemplate>
        <asp:GridView ID="GridView1" runat="server" CssClass="floatLeft"  
        AutoGenerateColumns="false"
        OnRowCommand="GridView1_RowCommand">  

         <Columns>
          <asp:ButtonField  ButtonType="Button" Text="ADD" CommandName="addrow" />
          <asp:BoundField DataField="data" HeaderText="data"/>
        </Columns>

        </asp:GridView>
        </ContentTemplate>

        <Triggers>
        <asp:PostBackTrigger ControlID="GridView1" />
        </Triggers>
 </asp:UpdatePanel>  

ASPX.CS:

List<string> test2 = new List<string>();
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "addrow")
            {

                    int index = Convert.ToInt32(e.CommandArgument);
                    GridViewRow selectedrow = GridView1.Rows[index];
                    string test = selectedrow.Cells[1].Text;
                    test2.Add(test);
                    ViewState["test2"] = test2;
            }

        }
4

0 回答 0