Thanks Philip. I have got it working now.
"Phillip Williams" wrote:
> 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 >
>
> "Derek" wrote:
>
> > 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
> >
> >
> > "Phillip Williams" wrote:
> >
> > > 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 > > >
> > >
> > > "Derek" wrote:
> > >
> > > > 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
> > > >