Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
| Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 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 Professionals 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 September 29th, 2009, 11:09 PM
Authorized User
 
Join Date: Dec 2007
Location: , , Vietnam.
Posts: 59
Thanks: 9
Thanked 0 Times in 0 Posts
Post Conversion from type 'DBNull' to type 'String' is not valid.

Hello all

There is a binding column which may be return as NULL from DataList or not. If it is not NULL then i ve to apply the Replace function

<asp:HyperLink ID="hplHotelName" CssClass="linkhotel" runat="server" NavigateUrl='<%# "/hotel/" & IIF(Eval("URLTitle") Is DBNull.Value,Replace(Replace(lcase(Eval("HotelName "))," ","-"),"&","and") & ".aspx",replace(Eval("URLTitle")," ","-") & ".aspx" ) %>' Text='<%# Eval("HotelName") %>'> </asp:HyperLink>

and i have also to check with the function like
<asp:HyperLink ID="hplHotelName" CssClass="linkhotel" runat="server" NavigateUrl='<%# "/hotel/" & IIF(Eval("URLTitle") <> "",Replace(Replace(lcase(Eval("HotelName"))," ","-"),"&","and") & ".aspx",replace(Eval("URLTitle")," ","-") & ".aspx" ) %>' Text='<%# Eval("HotelName") %>'> </asp:HyperLink>

For function both are not work.

Thanks for all thing
Phuc Hoang
 
Old September 30th, 2009, 02:31 PM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default What DB?

What DB are you using? MSSQL, MYSQL, ACCESS,...?


Assuming you are using MSSQL why don't you use an isnull() function to convert the null value to an empty string? that whay you don't need to check if the value is null.

something like this
Code:
Select HotelName, IsNull(URLTitle,HotelName) As URLTitle
Code:
<asp:HyperLink ID="hplHotelName" CssClass="linkhotel" runat="server" NavigateUrl='<%# "/hotel/" & Eval("URLTitle").ToString.Replace(" ","-").Replace("&","and") & ".aspx" %>' Text='<%# Eval("HotelName").ToString %>'> </asp:HyperLink>
also i think you have to use an HTML Anchor Tag for this because server controls don't allow <% %> constructs but i don't remember if that applies on databinding, i don't think it does?

Code:
<a id="hplHotelName" cass="linkhotel" href='<%# "/hotel/" & Eval("URLTitle").ToString.Replace(" ","-").Replace("&","and") & ".aspx" %>'><%# Eval("HotelName").ToString %></a>
Either way it would be much simpler to just do this in your Query. You could even do the replace function in the query as well if you wanted to.
__________________
Jason Hall

Follow me on Twitter @jhall2013
 
Old September 30th, 2009, 08:37 PM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

I think that's a bad idea. You should test if the value is null, then execute separate instructions based on the test results.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old October 1st, 2009, 02:01 AM
Authorized User
 
Join Date: Dec 2007
Location: , , Vietnam.
Posts: 59
Thanks: 9
Thanked 0 Times in 0 Posts
Default

Thanks alliancejhall
I have done it.
I am very pleasant with your helping me
Best wishes
Phuc Hoang
 
Old October 1st, 2009, 09:46 AM
Friend of Wrox
 
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Great...

Glad to hear it worked for you.
__________________
Jason Hall

Follow me on Twitter @jhall2013




Similar Threads
Thread Thread Starter Forum Replies Last Post
Conversion from type 'DBNull' to type 'String' is GailCG ASP.NET 2.0 Basics 5 February 22nd, 2007 03:12 PM
Cast from string to type Double not valid mika27 ASP.NET 2.0 Basics 0 January 31st, 2007 05:52 AM
Conversion from type 'DBNull' to type 'Boolean' is steve35719 VB Databases Basics 4 June 29th, 2006 06:13 PM
Cast from string "" to type 'Integer' is not valid h3x SQL Server ASP 1 January 30th, 2005 09:35 PM





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