在点“编辑”按钮前先判断一下当前行中的某一字段值啊?比如当前行中字段f中的值是‘Y’时就出现不能编辑的提示,然后返回,先谢谢大家了
解决方案 »
- 麻烦帮忙看错在哪儿?在线等。。。
- VS2010reportview导出excel表里边的都是乱码怎么办?????
- asp.net中c#,textbox如何动态绑定sql数据库中某条记录
- 如何在页面内点击一个链接,得到自身的html代码
- 怎么判断PostBack是通过按钮触发的
- 从Excel中导入数据到DataSet中,然后绑定到DataGrid中发现有的内容没有读出来??
- DropDownList数据填充问题`
- 我想用映射架构(XSD)的方式从SqlServer中每次取得10条数据怎么办呀?!如何写XPath?(200分)
- .net真让我不安。关于asp.net用户无法登录的问题????????帮帮我吧
- 关于datagrid的Columns集合的问题
- for循环插入数据问题!在线等,急救
- 通过ASP.NET使excel导入到数据库,请高手指点!急救,在线等。
{
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();
}
}
{
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;
}
}
}
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决定是否弹出警告。
{
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;
}
}
}
{
((Button)e.Item.FindCotrol("Edit")).Attributes.Add("onclick","javascript:check('" + DataBinder.Eval(e.Item.DataItem,"f") + "')");
}然后就可以判断了
function check(status)
{
if(status == 'y')
{
alert("不能编辑");
return false;
}
}
</script>
谢谢大家的热情参与!
if (e.Row.Cells[2].Text.Trim() != "OK")
{ e.Row.Cells[0].Enabled = false; }
可是为什么将值是OK的行的按钮也不能用了?
但是我将if (e.Row.Cells[2].Text.Trim() != "OK")这句改为if (e.Row.Cells[2].Text.Trim() == "OK")时竟然所有行的按钮都能用!这是什么原因?