本例依前方欄位值條件,如未鎖則可編輯及刪除,如前方欄位為已鎖,則停用編輯及刪除。
在GridView進行RowDataBound時,檢查Cell值為已鎖或未鎖並決定是否Disable編輯及刪除之功能。

VB
Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)Handles Gridview1.RowDataBound
If e.Row.Cells(6).Text.Trim() = "已鎖" Then
DirectCast(e.Row.Cells(7).Controls(0), WebControl).Enabled = False
DirectCast(e.Row.Cells(8).Controls(1), WebControl).Enabled = False
End If
End Sub
C#
private void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.Cells[6].Text.Trim() == "已鎖") {
((WebControl)e.Row.Cells[7].Controls[0]).Enabled = false;
((WebControl)e.Row.Cells[8].Controls[1]).Enabled = false;
}
}
全站熱搜