2014年5月9日 星期五

GridView依前方欄位值條件disable編輯及刪除鈕

資料來源:
http://adamschen9921.pixnet.net/blog/post/91648159-gridview%E4%BE%9D%E5%89%8D%E6%96%B9%E6%AC%84%E4%BD%8D%E5%80%BC%E6%A2%9D%E4%BB%B6disable%E7%B7%A8%E8%BC%AF%E5%8F%8A%E5%88%AA%E9%99%A4%E9%88%95

本例依前方欄位值條件,如未鎖則可編輯及刪除,如前方欄位為已鎖,則停用編輯及刪除。
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;
}
}

沒有留言: