0

嗨,我有一个表,其中有一列 AllowStockEdit,有点

我正在尝试检查用户是否具有编辑权限,然后在 radgridview 上显示编辑和删除按钮

这是我正在使用的代码

    protected void AccessLevels(object sender, EventArgs e)
{
    LINQDataContext dc = new LINQDataContext();
    UserPermission up = dc.UserPermissions.Where(a => a.ID == (int)Session["Permission"]).SingleOrDefault();
    up.AllowStockEdit = true;
}

    /*show hide buttons */

    protected void SelectedStockGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // show the edit button when user has correct access level

            if  
            {
                Button btnEdit = (Button)e.Row.FindControl("ShowEditButton");
                Button btndelete = (Button)e.Row.FindControl("ShowDeleteButton");

                btnEdit.Visible = true;
                btndelete.Visible = true;

            }
        }
    }

我正在尝试检查用户是否显示按钮是否具有编辑权限

任何帮助表示赞赏

4

1 回答 1

1

像这样的东西:

 protected bool AccessLevels()
{
    LINQDataContext dc = new LINQDataContext();
    return dc.UserPermissions.Where(a => a.ID == (int)Session["Permission"]).SingleOrDefault().AllowStockEdit;

}

 protected void SelectedStockGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // show the edit button when user has correct access level

            if(AccessLevels() == true) 
            {
                Button btnEdit = (Button)e.Row.FindControl("ShowEditButton");
                Button btndelete = (Button)e.Row.FindControl("ShowDeleteButton");

                btnEdit.Visible = true;
                btndelete.Visible = true;

            }
        }
    }
于 2013-02-13T15:47:51.417 回答