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 に答える