2013-02-13 79 views
0
檢索結果

您好我有其中有一列AllowStockEdit這是一個有點嘗試使用LINQ

我想檢查是一個表中的用戶擁有編輯權限,然後顯示上編輯並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

類似的東西:

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; 

      } 
     } 
    }