当我按下编辑然后按下按钮以应用它没有做任何事情的更改时,我的gridview行更新按钮不起作用。我错过了什么吗?
我的代码看起来像这样
C#
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string afspraak = ((TextBox)(GridView1.Rows[e.RowIndex].FindControl("EditAfspraak"))).Text;
string uitleg = ((TextBox)(GridView1.Rows[e.RowIndex].FindControl("EditUitleg"))).Text;
int id = Convert.ToInt32(((TextBox)(GridView1.Rows[e.RowIndex].FindControl("EditID"))).Text);
_controller.RecordUpdatenTblAfspraken(afspraak, uitleg, id);
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
}
ASP.NET
无法正确粘贴它,所以它在这里:
答案 0 :(得分:1)
更改EditIndex
后,您必须重新绑定网格。
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GridView1.DataSource = mijnDatabaseBron;
GridView1.DataBind();
}
同样适用于GridView1_RowCancelingEdit
以及GridView1_RowUpdating
中的更新成功。这假设您已将OnRowEditing
,OnRowCancelingEdit
和OnRowUpdating
事件添加到GridView。
同样在user7415073
注释时,GridView的绑定必须在IsPostBack
项检查中。
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GridView1.DataSource = mijnDatabaseBron;
GridView1.DataBind();
}
}
请在此处查看我的答案,了解如何轻松地将EditID
传递给后面的代码。
Get old value of label inside GridView during RowUpdating (ASP.NET GridView) C#