473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 4143
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
3
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I...
3
by: Wayne Wengert | last post by:
I am trying to impliment the extensions to the Club Starter kit as described at: http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/extendclubwebsitesk.asp but when I...
1
by: Carlos | last post by:
Hi all, I need a field that it is both databound, and hyperlink in a gridview. That is, the value is obtained from a query, and at the same time needs to point to a new page where will be used...
3
by: William LaMartin | last post by:
I have a gridview (with no properties set) on an aspx page which I populate from an XML file with the code below. The data in the XML file looks like this <description>National Trust for...
0
by: Neozaid | last post by:
I am trying to display records from an SQL database using an ASP.Net GridView control but I would like for one of the columns to be a Hyperlink or Hyperlink fields. Im using a DataTable to get the...
1
by: Frank Milverckowitz | last post by:
Hi, I'm trying to do something common and what should be simple using the GridView "Add Columns" feature in Visual Studio 2005. All I want to do is add a Hyperlink column that will take the...
1
by: Paul W Smith | last post by:
The text below is a GridView I am trying to use to display some data from a database. I am using one templatefield of grid because I want the contents of the record fields to appear on three...
2
by: Andy B | last post by:
I don't know if this is even working or not but here is the problem. I have a gridview that I databound to a dictionary<string, stringcollection: Contract StockContract = new Contract();...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.