Groups | Blog | Home
all groups > asp.net webcontrols > february 2006 >

asp.net webcontrols : Accessing the value in a bound control from VB


Derek
2/27/2006 4:29:32 AM
I want to make a button visible/invisible depending on who is logged in.

I am getting the user name from System.Environment.UserName and then
refreshing a SQLDataSource which uses the login name as a parameter to return
the permissions for the user.

I can display the value in a details view but how do I use this value in
code to make the button invisible?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim AD As New ADUser.ActiveDirectory()

If Not Page.IsPostBack Then
'Get the login name of the current user
Label1.Text = AD.UserName()

'Refresh the value in DetailsView1 based on the current user
SqlDataSource5.DataBind()

If Me.DetailsView1.Fields.Item(0) = 1 Then
Me.Button1.Visible = True
Else
Me.Button1.Visible = False
End If
End If
End Sub

Phillip Williams
2/28/2006 10:15:26 AM
Try databiding the Visible property of the ButtonField or CommandField to the
field that contains the condition, e.g.

Visible='<%# Eval("DisplayCondition")%>'

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


[quoted text, click to view]
Derek
3/1/2006 1:00:28 AM
It is not making the button visible/invisible that is the problem. I can't
read the value in Me.DetailsView1.Fields.Item(0).

This code displays an error.

If Me.DetailsView1.Fields.Item(0) = 1 Then
--
Derek


[quoted text, click to view]
Phillip Williams
3/1/2006 4:37:27 AM
Derek,

The proper place to access the data is during the DataBound event. As I
mentioned in my previous reply you could have done that declaratively. I put
a demo here for you where I used both strategies:
http://www.webswapp.com/codesamples/aspnet20/detailsview/default.aspx

You can review the source code to see how this can be done.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


[quoted text, click to view]
Derek
3/6/2006 3:46:32 AM
Thanks Philip. I have got it working now.
--
Derek


[quoted text, click to view]
AddThis Social Bookmark Button