如何根据行条件禁用网格视图中的编辑模式。 [英] How to disable the edit mode in grid view based on row condition.
本文介绍了如何根据行条件禁用网格视图中的编辑模式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为sign off的列,如果列值为Yes,则网格视图行不应该是可编辑的。
什么我试过了:
I have a column called "sign Off" and if the column value is "Yes" then the grid view row should not editable.
What I have tried:
protected void grdChangeRequirement_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);
Label myTextBox = row.FindControl("lbl_SignOff") as Label;
if (myTextBox.ToString() == "Yes")
{
Label btnUpdate = row.FindControl("btn_Update") as Label;
Label btnCancel = row.FindControl("btn_Cancel") as Label;
btnUpdate.Visible = false;
btnCancel.Visible = false;
}
}
推荐答案
使用RowDataBound [ ^ ]活动
标签
控制你必须使用Text
属性来读取文本值
我怀疑命令按钮不是标签,它应该是按钮或链接按钮控件。请检查并更改转换控件
use RowDataBound[^] Event
forlabel
control you will have to use theText
property to read the text value
I suspect the command buttons are not labels, it should be a button or linkbutton control. please check that and change the casting control
void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) {
GridViewRow row = (GridViewRow)e.Row;
Label myTextBox = row.FindControl("lbl_SignOff") as Label;
if (myTextBox.Text == "Yes")
{
LinkButton btnUpdate = row.FindControl("btn_Update") as LinkButton;
LinkButton btnCancel = row.FindControl("btn_Cancel") as LinkButton;
btnUpdate.Visible = false;
btnCancel.Visible = false;
}
}
}
这篇关于如何根据行条件禁用网格视图中的编辑模式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文