ASP.net的GridView:隐藏编辑|删除链接 [英] ASP.net GridView: hide Edit|Delete links

查看:269
本文介绍了ASP.net的GridView:隐藏编辑|删除链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的GridView使用的 AutoGenerateDeleteButton = TRUE 的&放大器;&安培;的 AutoGenerateEditButton属性=真的。
我希望只允许注册用户,因此要使用这些功能,我想从未注册用户隐藏。如何隐藏的?

I have GridView with AutoGenerateDeleteButton=true && AutoGenerateEditButton=true. I want to allow only registered users to use these functions therefore I want to hide it from unregistered users. How can I hide it?

我试过hidding整列,但在Page_Load中的GridView还没有准备好,所以我得到空例外。

I tried hidding the whole column but on page_load gridView is not ready yet so I get null exception.

推荐答案

在内部会议的页面加载事件存储用户角色

On your pageLoad event store user Role inside Session

 protected void Page_Load(object sender, EventArgs e)
{
    Session["usrRole"] = "1";
}

在您的会话和放gridview的检查排数据绑定事件;如果不是等于你的管理员角色,设置您的删除按钮栏的可见性为false

On Row databound event of your gridview check for the session & if not equal to your administrator role, set visibility of your delete button column to false

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (Session["usrRole"] != "1")
        {
            e.Row.Cells[0].Visible = false;   //0 is autogenerate edit column index
            e.Row.Cells[1].Visible = false;  // 1  is autogenerate delete column index
        }
    }
}

这篇关于ASP.net的GridView:隐藏编辑|删除链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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