尝试使用linq检索结果

时间:2013-02-13 15:25:48

标签: linq

您好我有一个表有一个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;

            }
        }
    }

我正在尝试检查用户是否具有编辑权限,如果他们确实显示了按钮

任何帮助表示赞赏

1 个答案:

答案 0 :(得分: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;

            }
        }
    }