you are doing the data binding every time the page is loaded, that is why you have the old value for the textbox, tryprivate void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { DataGrid1.DataSource=(ArrayList)Session["cart"]; DataGrid1.DataBind(); } }
但是这样有个问题,我在这个TEXTBOX输入的值并没有马上绑定,
((TextBox)e.Item.Cells[n].FindControl("TextBox1")).Text是以前的值,
就是说我想改变TEXTBOX的值,并且马上绑定到新值
有什么好办法吗?
{
//binding your controls using some data source
}
<asp:TemplateColumn HeaderText="数量">
<HeaderStyle Width="50px"></HeaderStyle>
<ItemTemplate>
<asp:TextBox Runat="server" Width="40" Text='<%# DataBinder.Eval(Container.DataItem, "GoodsCount") %>' ID="Textbox1" >
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn><asp:TemplateColumn HeaderText="更新">
<HeaderStyle Width="50px"></HeaderStyle>
<ItemTemplate>
<asp:LinkButton Runat="server" CommandName="update" Text="更新" ID="Linkbutton1"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
在CS文件中
public void ItemCommand(object sender, DataGridCommandEventArgs e)
{
if(e.CommandName=="update")
{
((cart)((ArrayList)Session["cart"][e.Item.ItemIndex]).GoodsCount=Convert.ToInt32(((TextBox)e.Item.Cells[3].FindControl("TextBox1")).Text);
}
}我把DATAVIEW是一个数组(ArrayList)Session["cart"],
就是我想在’数量‘这个TEXTBOX中输入新的值,然后在更新按钮中更新数量,就把输入的值重新写到这个数组中
麻烦你给看一下了
private void Page_Load(object sender, System.EventArgs e)
{
DataGrid1.DataSource=(ArrayList)Session["cart"];
DataGrid1.DataBind();
}
{
if (!IsPostBack)
{
DataGrid1.DataSource=(ArrayList)Session["cart"];
DataGrid1.DataBind();
}
}