禁用GridView Rowdatabound中的动态按钮

时间:2012-11-28 13:25:20

标签: asp.net

我想禁用绑定到该Grid的Button Control。 我正在使用btnTestMod.Enabled = false; 但它显示“System.NullReferenceException:对象引用未设置为对象的实例。”请建议纠正。

protected void gvRootModule_RowDataBound(object sender, GridViewRowEventArgs e)
    {
      if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Button btnTestMod = ((Button)e.Row.FindControl("btnlessontest"));
        }
    }

1 个答案:

答案 0 :(得分:-1)

protected void gvRootModule_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
    {
        var button = e.Row.FindControl("btnlessontest") as Button;
        if(button == null) return;

        button.Enabled = false;
    }
}
相关问题