Only show hyperlink text in asp.net 2 gridview if database column is not empty

Discussion in 'ASP .Net' started by Bren, Aug 23, 2006.

  1. Bren

    Bren Guest

    Hi All

    VS2005 Gridview control with vb

    I am populating a gridview of company staff.
    One of the columns is a hyperlink to a SMS texting facility I have so
    secrataries can text the managers etc.
    i.e Secratary loads the page on the intranet, finds the manager they want to
    contact, clicks on the "SMS" hyperlink and is taken to the SMS page to fill
    out the message and send it to the manager.

    My issue is that not all managers have mobile phones so I only want to show
    the "SMS" hyperlink text if the "mobile" database column has a number in it.

    I am pretty sure the Eval() function with a template field is what I need
    but I am unsure how to use this so some pointers and sample code would be
    very much appreciated here.

    TIA
    Bren
     
    Bren, Aug 23, 2006
    #1
    1. Advertising

  2. Bren

    David Wier Guest

    What you need is a 'helper' function, to check the data when it is returned
    from the database -
    Function CheckData(sItem as text) as text
    if sItem is System.DBNull.Value Then
    CheckData=""
    else
    CheckData= ' build your hyperlink here
    end if
    End Function

    Then, put the function around the eval statement - something like:
    CheckData(Eval(YourDBfield))

    This is all ottomh, so it could take a little tweaking
    :)

    --
    David Wier
    MVP/ASPInsider
    http://aspnet101.com
    http://aspexpress.com


    "Bren" <> wrote in message
    news:...
    > Hi All
    >
    > VS2005 Gridview control with vb
    >
    > I am populating a gridview of company staff.
    > One of the columns is a hyperlink to a SMS texting facility I have so
    > secrataries can text the managers etc.
    > i.e Secratary loads the page on the intranet, finds the manager they want

    to
    > contact, clicks on the "SMS" hyperlink and is taken to the SMS page to

    fill
    > out the message and send it to the manager.
    >
    > My issue is that not all managers have mobile phones so I only want to

    show
    > the "SMS" hyperlink text if the "mobile" database column has a number in

    it.
    >
    > I am pretty sure the Eval() function with a template field is what I need
    > but I am unsure how to use this so some pointers and sample code would be
    > very much appreciated here.
    >
    > TIA
    > Bren
    >
    >
     
    David Wier, Aug 23, 2006
    #2
    1. Advertising

  3. Bren

    Bren Guest

    Hi David

    Thanks for that I will go away and play with that and post back my results.

    Regards
    Bren

    Why do I climb mountains? Simple! because they are there
    www.3peakschallenge.co.uk

    "David Wier" <> wrote in message
    news:O%23h$...
    > What you need is a 'helper' function, to check the data when it is
    > returned
    > from the database -
    > Function CheckData(sItem as text) as text
    > if sItem is System.DBNull.Value Then
    > CheckData=""
    > else
    > CheckData= ' build your hyperlink here
    > end if
    > End Function
    >
    > Then, put the function around the eval statement - something like:
    > CheckData(Eval(YourDBfield))
    >
    > This is all ottomh, so it could take a little tweaking
    > :)
    >
    > --
    > David Wier
    > MVP/ASPInsider
    > http://aspnet101.com
    > http://aspexpress.com
    >
    >
    > "Bren" <> wrote in message
    > news:...
    >> Hi All
    >>
    >> VS2005 Gridview control with vb
    >>
    >> I am populating a gridview of company staff.
    >> One of the columns is a hyperlink to a SMS texting facility I have so
    >> secrataries can text the managers etc.
    >> i.e Secratary loads the page on the intranet, finds the manager they want

    > to
    >> contact, clicks on the "SMS" hyperlink and is taken to the SMS page to

    > fill
    >> out the message and send it to the manager.
    >>
    >> My issue is that not all managers have mobile phones so I only want to

    > show
    >> the "SMS" hyperlink text if the "mobile" database column has a number in

    > it.
    >>
    >> I am pretty sure the Eval() function with a template field is what I need
    >> but I am unsure how to use this so some pointers and sample code would be
    >> very much appreciated here.
    >>
    >> TIA
    >> Bren
    >>
    >>

    >
    >
     
    Bren, Aug 23, 2006
    #3
  4. Bren

    Bren Guest

    Hi David

    After a bit of tweaking with your suggestion I got it to work as follows:-

    In the code behind page I created the following function
    Function CheckMobile(ByVal sItem As String) As String

    If Len(sItem) > 1 Then

    CheckMobile = "SMS"

    Else

    CheckMobile = ""

    End If

    End Function

    And then in the webform Itemtemplate I did this

    <ItemTemplate>

    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#
    Eval("mobile", "~/smscenter/Default.aspx?mob={0}") %>'

    Text='<%# CheckMobile(Eval("mobile", "")) %>'></asp:HyperLink>

    </ItemTemplate>

    Now works a treat

    Thanks very much for your help

    Rgds
     
    Bren, Aug 23, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. davetichenor
    Replies:
    1
    Views:
    914
    Eliyahu Goldin
    Oct 30, 2006
  2. Replies:
    2
    Views:
    463
  3. Keith G Hicks
    Replies:
    3
    Views:
    810
    Keith G Hicks
    Feb 18, 2008
  4. Dave
    Replies:
    0
    Views:
    1,002
  5. John B. Matthews
    Replies:
    0
    Views:
    785
    John B. Matthews
    Dec 9, 2011
Loading...

Share This Page