I have a Gridview that containes some users values. I want to set 2 butons to visible=false if the logon user is "admin". For one user it's working fine, and for another not. I have no idea why. This is my code:
Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If (e.Row.RowState = DataControlRowState.Edit) OrElse (e.Row.RowState = (DataControlRowState.Alternate Or DataControlRowState.Edit)) Then
Else
Dim UserName As String = User.Identity.Name
Dim usern As String = DirectCast(e.Row.FindControl("label3"), Label).Text
Dim edytuj As Button = DirectCast(e.Row.FindControl("button1"), Button)
Dim rola As String = DirectCast(e.Row.FindControl("label1"), Label).Text
Dim usuń As Button = DirectCast(e.Row.FindControl("button3"), Button)
If UserName.Equals(usern) And rola.Equals("admin") Then
edytuj.Visible = False
usuń.Visible = False
End If
End If
End If
End Sub
This is data from my database. For user "spontan23" those buttons are not showing. But when I log for user "Kondi75" those buttons are shown for him and it shouldn't be.
I want to check if user that is logon is an admin. I want to set for that kind of user edit button visible false, so that won't be a situation where there is no admin. But he should be able to change rule for other users.
Spontan23
Member
345 Points
314 Posts
Get buttons visible false
May 06, 2012 11:11 AM|LINK
Hi,
I have a Gridview that containes some users values. I want to set 2 butons to visible=false if the logon user is "admin". For one user it's working fine, and for another not. I have no idea why. This is my code:
Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If (e.Row.RowState = DataControlRowState.Edit) OrElse (e.Row.RowState = (DataControlRowState.Alternate Or DataControlRowState.Edit)) Then Else Dim UserName As String = User.Identity.Name Dim usern As String = DirectCast(e.Row.FindControl("label3"), Label).Text Dim edytuj As Button = DirectCast(e.Row.FindControl("button1"), Button) Dim rola As String = DirectCast(e.Row.FindControl("label1"), Label).Text Dim usuń As Button = DirectCast(e.Row.FindControl("button3"), Button) If UserName.Equals(usern) And rola.Equals("admin") Then edytuj.Visible = False usuń.Visible = False End If End If End If End SubAmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Get buttons visible false
May 06, 2012 11:14 AM|LINK
Hey
what do u mean by " For one user it's working fine, and for another not. "
Spontan23
Member
345 Points
314 Posts
Re: Get buttons visible false
May 06, 2012 11:26 AM|LINK
NULL
Spontan23
Member
345 Points
314 Posts
Re: Get buttons visible false
May 06, 2012 11:28 AM|LINK
This is data from my database. For user "spontan23" those buttons are not showing. But when I log for user "Kondi75" those buttons are shown for him and it shouldn't be.
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Get buttons visible false
May 06, 2012 12:33 PM|LINK
try to make your if statment as following
If rola.toSring() = ("admin") Then edytuj.Visible = False usuń.Visible = False End Ifsince if you don't the admin see these button just check this condition ,, why are you checking the name?Spontan23
Member
345 Points
314 Posts
Re: Get buttons visible false
May 06, 2012 01:54 PM|LINK
It didn't work. I check it on other users and only this one works fine. I mean "spontan23". Maybe it's because of some cookies?
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Get buttons visible false
May 06, 2012 02:01 PM|LINK
you only need to check if he is admin right
now your labels are getting data from database.
and in both users role should be admin, try to debug and make sure that rola.toString is "admin"
so check
Spontan23
Member
345 Points
314 Posts
Re: Get buttons visible false
May 06, 2012 06:48 PM|LINK
I want to check if user that is logon is an admin. I want to set for that kind of user edit button visible false, so that won't be a situation where there is no admin. But he should be able to change rule for other users.