本文介绍了如何根据用户角色设置控件的可见性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!!!
我有2个角色admin和user.他们俩都可以访问同一页面(default.aspx).此页面具有带有update和delete按钮的gridview.我想做的是禁用删除和编辑按钮,或者如果用户处于"USER"角色则将其隐藏.

请告诉我该怎么做.

Hello!!!
I have 2 roles admin and user. They both have access to same page (default.aspx) This page has a gridview with update and delete button. what i want to do is disable the delete and edit button or hide them if user is in role "USER".

Please tell me how to do this.

推荐答案

Protected Sub GridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        Dim rtype As DataControlRowType = e.Row.RowType
        If ((rtype = DataControlRowType.DataRow)  _
                    AndAlso ((rtype <> DataControlRowType.Footer)  _
                    AndAlso ((rtype <> DataControlRowType.Separator)  _
                    AndAlso ((rtype <> DataControlRowType.Header)  _
                    AndAlso (rtype <> DataControlRowType.Pager))))) Then
            ' Get the delete button 
            ' Use Role
            ' Disable if not Admin
            If (currentRole <> "Admin") Then
                Dim btn As Button = CType(e.Row.FindControl("DeleteButton1"),Button)
                btn.Enabled = false
            End If
        End If
    End Sub


试试吧!


Try!


这篇关于如何根据用户角色设置控件的可见性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 09:25
查看更多