469,946 Members | 1,928 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,946 developers. It's quick & easy.

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

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
Aug 23 '06 #1
3 3964
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" <me@dontbothertoemail.comwrote in message
news:OC**************@TK2MSFTNGP03.phx.gbl...
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


Aug 23 '06 #2
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" <da********@noSpamhotmail.comwrote in message
news:O%****************@TK2MSFTNGP05.phx.gbl...
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" <me@dontbothertoemail.comwrote in message
news:OC**************@TK2MSFTNGP03.phx.gbl...
>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



Aug 23 '06 #3
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
Aug 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by TPhelps | last post: by
3 posts views Thread by Wayne Wengert | last post: by
3 posts views Thread by William LaMartin | last post: by
1 post views Thread by Frank Milverckowitz | last post: by
1 post views Thread by Paul W Smith | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.