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

解决方案 »

  1.   

    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();
            }
        }
      

  2.   

    直接不显示。  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;
                }
            }
        }
      

  3.   

    //禁用也蛮好,复制  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;
                }
            }
        }
      

  4.   

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

  5.   

    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;
            }
        }
    }
      

  6.   

    这个是我测试的,改成你的就是
    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;
            }
        }
    }
      

  7.   

    DataBound 事件if(e.Item.ItemIndex >= 0)
    {
      ((Button)e.Item.FindCotrol("Edit")).Attributes.Add("onclick","javascript:check('" + DataBinder.Eval(e.Item.DataItem,"f") + "')");
    }然后就可以判断了
      

  8.   

    <script>
    function check(status)
    {
      if(status == 'y')
    {
       alert("不能编辑");
       return false;
    }
    }
    </script>
      

  9.   

    我还是想能有个提示框,也不想把编辑按钮隐藏,一楼xlshen_lxz()老师的代码虽然出来了提示框,但仍然可以编辑,我在提示语句后Page.ClientScript.RegisterStartupScript(this.GetType(), "Cannot Edit", "<script language='javascript'>alert('不能编辑!')</script>");后边加了 this.myGridView.EditIndex =-1;想取消编辑状态,可是不起作用,但是如果我把 this.myGridView.EditIndex =-1这条语句单独放到另一个按钮中执行时就能起作用,这是什么原因啊?
    谢谢大家的热情参与!
      

  10.   

    还有啊,我现在做了以下测试,我想根据表格中的第三列值是否是“OK”将第一列的按钮失效或能用,我在RowDataBound中用下列代码测试,
    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")时竟然所有行的按钮都能用!这是什么原因?