当前位置:编程学习 > C#/ASP.NET >>

如何获取GridView中的按钮

我想在自已写的方法中去获取到GridView中的按钮,并去设置它是否可用,该如何获取

注意,并不是在Command方法中去获取 --------------------编程问答-------------------- 一般gridview的按钮都在第一列,你想把它禁用的话,或者对某些人禁用的话

可以采用把这一列给禁用了,或者给Visible 给设置false




              if (strUserName == "小明")
            {
                this.ASPxGridView1.Columns[0].Visible = true;
            }
            else 
            {
                this.ASPxGridView1.Columns[0].Visible = false;
            }     
--------------------编程问答-------------------- 不好意思,如果想不在command里面解决好像不可能,
在command里面可以设置keyname主键来查找或者是通过所在的列进行查找,不过也很期待不用command查找的方法,顶之~ --------------------编程问答--------------------
 Button btn = this.GridView1.Rows[1].FindControl("button1") as Button;

        btn.Attributes.Add("onclick", "return confirm('aaaaaaaaaa')");
--------------------编程问答--------------------
Button btn = this.GridView1.Rows[1].FindControl("button1") as Button;

        btn.Attributes.Add("onclick", "return confirm('aaaaaaaaaa')");
//代码可以直接丢在page_load里面

//进行操作用给按钮CommandName="aa"这个属性来完成
--------------------编程问答--------------------

Button tempButton = ((Button)(GridView1.Rows[行索引].Cells[列索引].FindControl("按钮名称")));
       tempButton.Enabled = false;
--------------------编程问答--------------------
引用 3 楼 zhoukang0916 的回复:
C# code Button btn=this.GridView1.Rows[1].FindControl("button1")as Button;

        btn.Attributes.Add("onclick","return confirm('aaaaaaaaaa')");

正解 --------------------编程问答-------------------- --------------------编程问答-------------------- 4 楼 --------------------编程问答-------------------- TextBox txtitbh=new TextBox ();
TextBox txtitunit=new TextBox ();
TextBox txtitnum=new TextBox ();
foreach (DataGridItem item in DataGrid1.Items)
{
if (item.ItemType == ListItemType.Item)
{
txtitunit = (TextBox)item.FindControl("txtLDLitUnit");
txtitbh = (TextBox)item.FindControl("txtLDLitBH");
txtitnum =(TextBox)item.FindControl("txtLDLitTime");
}

txtitbh.Text =ViewState["Ld_bh"].ToString ()+"("+ViewState["LD_xh"].ToString ()+")";
txtitunit.Text =ViewState["LD_unit"].ToString ();
txtitnum.Text =ViewState["LD_num"].ToString ();
参考下  我事在Page_Load里写的
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,