更新后需要在正常模式下进行操作

时间:2011-01-22 18:47:19

标签: c# .net asp.net gridview

我有一个带有“编辑更新取消”命令字段的网格视图。单击“编辑”时,特定行中的所有列都将变为可编辑状态,当我单击“更新”时,将根据新值更新表。 然后Gridview与更新的数据表绑定。但“更新取消”按钮仍然是 仍然存在。

alt text

一旦更新了行,“更新取消”按钮必须更改为“编辑”,那么这是如何实现的。

先谢谢

这是更新和显示更新数据的代码

 protected void StaticNoticeGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

            try
            {                
                //Gets the updated value from GridView
                string id = StaticNoticeGridView.Rows[e.RowIndex].Cells[0].Text;
                string updatedItem = e.NewValues[0].ToString();
                string updatedURL = e.NewValues[1].ToString();

                //Updated the Database
                StaticNoticeController staticNoticeController = new StaticNoticeController();
                int rocordsAffected = staticNoticeController.UpdateStaticNoticeData(updatedItem, updatedURL, id);

                //Gets the updated datatable and binds the Gridview again
                if (rocordsAffected == 1)
                {
                    this.StaticNoticeGridView.DataSource = null;
                    this.StaticNoticeGridView.DataSource = staticNoticeController.GetStaticNoticeData();
                    this.StaticNoticeGridView.DataBind();
                }
            }
            catch(SystemException ex)
            {
                //ToDo: Log the Exception
            }
        }

1 个答案:

答案 0 :(得分:11)

在方法this.StaticNoticeGridView.DataBind();中的StaticNoticeGridView_RowUpdating之前设置GridView1.EditIndex = -1;