我有一个带GridView的更新面板(数据绑定)。每行都有一个按钮。如果用户单击某个按钮,则该值将附加到列表中。我得到的问题是我只能存储由于回发而最后添加的值。那么有人可以告诉我正确的存储方式吗?
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;
}
}