2011-09-29 31 views
0

可能重複:
Disable the Edit button on all the rows when Edit button is clicked on a particular row in GridView如何禁用所有其他行除了在EDIT模式

如何禁用除了一個在編輯模式下,所有其他行?

我試圖找到一種方法來禁用所有其他行,而我在過程中的編輯模式,除了編輯之一。

這裏是我的gridview的樣子:

<gridview.... 
<edittemplate...> 
................ 
</edittemplate> 
............ 
<asp:CommandField ButtonType="Link" ItemStyle-HorizontalAlign="Center" SelectText="Select" 
EditText="Edit" UpdateText="Save" ShowEditButton="true" /> 
</Columns> 
</asp:GridView> 
+0

感謝您的鏈接,但我不usign''我使用'的

回答

1

您需要處理RowEditing事件的GridView的禁用除了編輯一個所有行。

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) 
    { 
     GridView1.EditIndex = e.NewEditIndex; 
     //Put binding code here.. 
     GridView1.DataBind(); 

     foreach (GridViewRow row in GridView1.Rows) 
     { 
      if (row.RowIndex != e.NewEditIndex) 
      { 
       row.Enabled = false; 
      } 
     } 
    } 

編輯:

除了這個代碼,請驗證Page_Load方法的綁定代碼。

protected void Page_load() 
{ 
    if(!IsPostBack) 
    { 
     //put GridView databinding code here 

    } 
} 
+0

並沒有真正的工作,我仍然可以點擊其他行.. –

+0

@AbuHamzah我沒有意識到你的代碼。請在page_load事件中向我展示數據綁定代碼。 – adatapost

+0

我使用'

相關問題