當Detail有資料列時,如何讓A欄位值為0時,設置該筆資料列為無法編輯?
可以在RowDataBound事件中處理,先將CommandField轉換成TemplateField,找到編輯按鈕的ID,參考代碼:
protected void wgvDetail_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowIndex != wgvDetail.EditItemIndex)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string text = e.Row.Cells[1].Text; //如果A欄位不是TemplateField;
string text = (e.Row.FindControl("labelA") as Label).Text; //如果A欄位是TemplateField
if (text == "0")
{
ImageButton edit = (ImageButton)e.Row.FindControl("ImageButtonEdit");
if (edit != null)
{
edit.Visible = false;
}
}
}
}
}