如果编辑、删除的按钮是自动产生的,那么就这样:
GridView1.AutoGenerateDeleteButton = false;
GridView1.AutoGenerateEditButton = false;
如果是手动添加上的,你看下图片就明白了:
首先
Session["Password"] == 123456
这有问题
Session 存储的object
还有密码一般用字符串
123456是int型
改成
密码为字符串类型
if(Session["Password"].ToString() == "123456")
{
this.GridView1.ShowDeleteButton = False;
this.GridView1.ShowEditButton = False;
}
else
{
this.GridView1.ShowDeleteButton = True;
this.GridView1.ShowEditButton = True;
}
或者
密码为值类型
if(Convert.ToInt32(Session["Password"]) == 123456)
{
this.GridView1.ShowDeleteButton = False;
this.GridView1.ShowEditButton = False;
}
else
{
this.GridView1.ShowDeleteButton = True;
this.GridView1.ShowEditButton = True;
}
好像只能GridView DataList控件中的生成事件中去找到控件,然后隐藏