Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 15th, 2009, 01:41 PM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default Hiding text in gridview if data doesn't exist

Hi
I am using the following code in a Gridview to display a link to generate an e-mail to an email address obtained from a database:
Code:
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:HyperLink ID="EmailLink" text='e-Mail' 
NavigateUrl='<%# Eval("eMail","mailto:{0}?Subject=Enquiry from Cobham Chamber Website")%>' 
runat="server"
target="_blank" />
</ItemTemplate>
I am using text='e-Mail' as I am restricted in width and the email address that will be displayed by using text='<%# Bind("eMail") %>' is too long.

The latter has the advantage that the column is blank if no e-mail address exists (ConvertEmptyStringtoNull set to TRUE)
But with text='e-mail' the records with an address get the word e-mail as a link whilst those without get the word e-Mail without a link.

Can I hide the text when there is no data in the field?
__________________
Geoff Baldwin
 
Old December 15th, 2009, 04:48 PM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

you can use
Code:
<asp:HyperLink ID="EmailLink" text='<%=Bind("eMail")=="" ? "e-Mail" : "" %>'
NavigateUrl='<%# Eval("eMail","mailto:{0}?Subject=Enquiry from Cobham Chamber Website")%>' 
runat="server"
 
Old December 15th, 2009, 08:10 PM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by irProject View Post
you can use
Code:
<asp:HyperLink ID="EmailLink" text='<%=Bind("eMail")=="" ? "e-Mail" : "" %>'
NavigateUrl='<%# Eval("eMail","mailto:{0}?Subject=Enquiry from Cobham Chamber Website")%>' 
runat="server"
Thanks for the suggestion -
What actually gets displayed is all the text between ' and ' after text=.
-as a link to an e-mail when one is present but as plain text when it isn't :(

I can see the idea is to put "e-mail" and a link in the field if an e-mail address exists and anull in the field if an e-mail address doesn't exist but don't know enough about the syntax to figure out what is actually wrong?

Something missing or extraneous in the syntax??
__________________
Geoff Baldwin

Last edited by SouthendSupporter; December 16th, 2009 at 06:00 AM.. Reason: Bad typos and missing sense!
 
Old December 17th, 2009, 09:16 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

I have used the following in a system (in the .aspx page within the code<asp:Hyperlink> </>
Code:
 
Visible='<%# IIf(Eval("ForumUser").ToString().Equals(Session("ForumUserID").ToString), "False","True" )%>'
Which checks the ForumUser Name on a record agains a session recording the logged in ID


So you will need to change ForumUser to Email and play around wth the Equals(Session("ForumUserID") bit to be either "" or NULL


Hope it helps.
The Following 2 Users Say Thank You to timeware For This Useful Post:
irProject (December 18th, 2009), SouthendSupporter (December 17th, 2009)
 
Old December 17th, 2009, 10:43 AM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by timeware View Post
I have used the following in a system (in the .aspx page within the code<asp:Hyperlink> </>
Code:
 
Visible='<%# IIf(Eval("ForumUser").ToString().Equals(Session("ForumUserID").ToString), "False","True" )%>'
Which checks the ForumUser Name on a record agains a session recording the logged in ID


So you will need to change ForumUser to Email and play around wth the Equals(Session("ForumUserID") bit to be either "" or NULL


Hope it helps.
BRILLIANT!!
Does just what I need -- many thanks
__________________
Geoff Baldwin





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on Hiding Charts with no data Wazar Excel VBA 4 December 19th, 2018 03:04 AM
gettting data from gridview in edit mode text cont mahboob_sabir ASP.NET 2.0 Professional 1 May 8th, 2007 02:05 AM
hiding empty text boxes in an Access report EricTheViking Access 4 September 7th, 2006 11:43 AM
Hiding text keystrokes for passwords mmcdonal Access VBA 4 March 16th, 2004 04:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.