怎样在Gridview中在点“编辑”按钮前判断一下当前行中的某一字段值啊在线随时结贴,该如何解决

怎样在Gridview中在点“编辑”按钮前判断一下当前行中的某一字段值啊?在线随时结贴
在点“编辑”按钮前先判断一下当前行中的某一字段值啊?比如当前行中字段f中的值是‘Y’时就出现不能编辑的提示,然后返回,先谢谢大家了

------解决方案--------------------
protected void myGridView_RowEditing(object sender, GridViewEditEventArgs e)
{
TextBox tb = (TextBox)myGridView.Rows[e.NewEditIndex].Cells[2].Controls[0];
if (tb.Text == "Y ")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Cannot Edit ", " <script language= 'javascript '> alert( '不能编辑! ') </script> ");
}
else
{
this.myGridView.EditIndex = e.NewEditIndex;
BindGrid();
}
}
------解决方案--------------------
直接不显示。 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView row = (DataRowView)e.Row.DataItem; if (row[ "f "].ToString() == "Y ") { e.Row.Cells[1].Controls[0].Visible = false; } } }
------解决方案--------------------
//禁用也蛮好,复制 cpp2017(慕白兄)的代码
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView row;
if (e.Row.RowType == DataControlRowType.DataRow)
{
row = (DataRowView)e.Row.DataItem;
if (row[ "f "].ToString() == "Y ")
{
e.Row.Cells[1].Controls[0].Enable = false;
}
}
}


------解决方案--------------------
禁用最好。上边说了,我就不写了。
一定要弹提示的话,也可以注册一段JS给“编辑”按钮(在DataBind的时候给当前行的按键注册)。找到需要判断的cell(用parent, child来发挥想象吧),根据value决定是否弹出警告。

------解决方案--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView row;
if (e.Row.RowType == DataControlRowType.DataRow)
{
row = (DataRowView)e.Row.DataItem;
if (Convert.ToBoolean(row[ "contract "]) == false)
{
((LinkButton)e.Row.Cells[0].Controls[0]).Enabled= false;
}
}
}
------解决方案--------------------
这个是我测试的,改成你的就是
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView row;
if (e.Row.RowType == DataControlRowType.DataRow)
{
row = (DataRowView)e.Row.DataItem;
if (row[ "f "].ToString().ToUpper() == "Y ")
{
((LinkButton)e.Row.Cells[0].Controls[0]).Enabled= false;
}
}
}

------解决方案--------------------
DataBound 事件

if(e.Item.ItemIndex > = 0)
{
((Button)e.Item.FindCotrol( "Edit ")).Attributes.Add( "onclick ", "javascript:check( ' " + DataBinder.Eval(e.Item.DataItem, "f ") + " ') ");
}

然后就可以判断了
------解决方案--------------------
<script>
function check(status)
{
if(status == 'y ')
{
alert( "不能编辑 ");
return false;
}
}
</script>