2011-08-19 33 views
1

我有Windows身份驗證運行在asp.net web應用程序更新的GridView允許根據用戶認證asp.net

我只希望特定用戶能夠更新,而其他用戶只能能夠查看。

如何自定義gridview,以便只有特定的用戶可以選擇更新?

+0

你是如何通過GridView做了更新。有很多方法可以給那隻貓蒙皮。 –

+0

@james我剛剛啓用了更新鏈接的東西 –

+0

所以你使用內置的編輯功能? –

回答

1

GridView控件綁定後,嘗試某處添加以下代碼:

CommandField editButton = GridView.Columns.OfType<CommandField>().ElementAtOrDefault(0); 
if (editButton != null) 
    editButton.Visible = HttpContext.Current.user.Identity.Name == "<USER NAME>"; 
+0

看起來像一個很棒的解決方案有沒有其他的,你可以想到的? –

+0

我也想問你這個:http://serverfault.com/questions/303184/configuring-asp-net-to-work-with-roles-in-windows-authentication –

+0

我認爲這可能是最簡單的解決方案情況。看你最後的評論,你是否想限制編輯到某個角色? –