2011-06-29 116 views
2

我正在使用可編輯GridView。點擊一行的編輯按鈕後,該行進入可編輯模式,一旦我更新當前行的詳細信息,該行即被保存並進入正常模式。以編程方式取消gridview行編輯模式使用C#

這裏我面臨一個問題。當我將行設置爲可編輯模式時,點擊一個按鈕(不是網格的一部分),我想將可編輯行模式設置爲正常模式。

回答

5

將gridview的EditIndex值更改爲-1。

protected void Button1_Click(object sender, EventArgs e) 
    { 
     GridView1.EditIndex = -1; 
    } 
4

你可以把這個在你的 「RowCancelingEdit」 事件

我的GridView的名字是grdViewDetails。

protected void grdViewDetails_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) 
     { 
      grdViewDetails.EditIndex = -1; 
      grdViewDetails.DataSource = YourDatasource; //a dataset in my case 

      //Bind data to the GridView control. 
      grdViewDetails.DataBind(); 
     }