Solved

Using conditional logic in VB to have LinkButton be visible (or not visible)

Posted on 2008-06-10
2
217 Views
Last Modified: 2013-11-07
I have a DataList that contains several Labels and a LinkButton in both the Item & Alternating Item Templates.  One of the labels, Label7, displays a numeric value.
My problem is this:  I only want LinkButton1 to be visible if the value of Label7 > 0
How do I do this with VB.NET?
Thanks in advance for any advice.
0
Comment
Question by:DanGettel
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 21751474
DataList can fire an event called ItemDataBound, you can use it to accomplish your mission.

Private Sub DataListl_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataListl.ItemDataBound

        If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
 

            Dim lbl As Label = CType(e.Item.FindControl("Label7"), Label)

            Dim lnkbtn As LinkButton = CType(e.Item.FindControl("myLinkButton"), LinkButton)

            If (lnkbtn IsNot Nothing) AndAlso (lbl IsNot Nothing) Then

                If (Int32.Parse(lbl.Text) > 7) Then

                   lnkbtn.Visible = True

                Else

                   lnkbtn.Visible = False

                End If

            End If

        End If

    End Sub

Open in new window

0
 
LVL 22

Assisted Solution

by:prairiedog
prairiedog earned 500 total points
ID: 21751496
Sorry, this line: Int32.Parse(lbl.Text) > 7
should be Int32.Parse(lbl.Text) >  0
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now