如何从同一页面上的按钮访问gridview控件 [英] how to access gridview controls from a button on same page

查看:81
本文介绍了如何从同一页面上的按钮访问gridview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个包含编辑和删除按钮的gridview.我能够访问这些控件并将其设置为control.Enabled = false.

但是,如何从同一页面的外部按钮执行相同的操作.就像当我单击名为批准交易的按钮时一样.我想禁用网格视图中的添加,编辑和删除按钮.

这是我的代码通过gvjvtemp_RowDataBound
访问控件

Hi,

I have a gridview that contains edit and delete button. I was able to access those controls and set them to control.Enabled=false.

However, how can I do the same thing from a button in the same page but outside. Like when I click a button called approve the transaction. I want to disable the add, edit and delete buttons in the grid view.

here is my code accessing the control via gvjvtemp_RowDataBound

protected void gvjvtemp_RowDataBound(object sender, GridViewRowEventArgs e)
{// added to apply security


#region Check security
//apply security
if (Global.enforceSecurity)
  if (!User.IsInRole("106") && !User.IsInRole("108")) //Lead TARP Accountant / TARP Accountant
  {
    btnAdd.Enabled = false;
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      if (e.Row.DataItem != null)
      {
        Button EditControl = (Button)e.Row.Cells[0].FindControl("lnkedit");
        Button DelelteControl = (Button)e.Row.Cells[1].FindControl("btndel");

        if (EditControl.Text == "Edit")
        {
          e.Row.Cells[0].Enabled = false;
        }
        if (DelelteControl.Text == "Delete")
        {
          e.Row.Cells[1].Enabled = false;
        }
      }
    }
  }
#endregion
}


谢谢

Al


Thanks

Al

推荐答案

单击按钮将导致回发,该回发将执行逻辑数据绑定网格并因此再次触发此事件.

您需要做的是设置类级别的变量,您可以在RowDataBound事件处理程序方法中检查该变量,并适当地设置控件.
The button click will cause a postback which will execute the logic for data binding the grid and thus triggering this event again.

What you need to do is set class level variable that you can check in the RowDataBound event handler method and set the controls appropriately.


这篇关于如何从同一页面上的按钮访问gridview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆