p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Basics (http://p2p.wrox.com/forumdisplay.php?f=60)
-   -   How to show text in datalist while value in NULL (http://p2p.wrox.com/showthread.php?t=57231)

nittin14 April 28th, 2007 01:10 AM

How to show text in datalist while value in NULL
 
hello guys,
pls solve my problem
my problem is that
i m retreive data from table but in some column the value is store NULL. i want that insist of NULL it wl display some text in datalist while data retreive from databse

Eg.
employee //table name

Date //column name

14/6/82
NULL
15/6/82

i want display it in this format

employee //table name

Date //column name

14/6/82
Date Not Filled
15/6/82

is it possible if yes then send me solution of this problem with the help of example.
thanks

mike_remember April 30th, 2007 02:04 AM

Depends how you are filling your datalist, one way could be checking for null from database itself using the ISNULL function, another way could be checking for null while binding, something like below:

<asp:Label Runat="server" ID="lblTest" text='<%#DataBinder.Eval(Container.DataItem,"no")= = DBNull.Value.ToString() ? "Date not filled" : DataBinder.Eval(Container.DataItem,"no")%>'>

There could be lot other ways too....

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.

nittin14 May 1st, 2007 12:59 AM

helo sir,
 this is not working
it is giving error:

 BC30201: Expression expected

i m using ur solution in datalist like this:

<%# DataBinder.Eval(Container.DataItem,"promotiondue") == DBNull.Value.ToString() ? "Date not filled" : DataBinder.Eval(Container.DataItem,"promotiondue") %>

but they r not executing
can u send the sloution


Quote:

quote:Originally posted by mike_remember
 Depends how you are filling your datalist, one way could be checking for null from database itself using the ISNULL function, another way could be checking for null while binding, something like below:

<asp:Label Runat="server" ID="lblTest" text='<%#DataBinder.Eval(Container.DataItem,"no")= = DBNull.Value.ToString() ? "Date not filled" : DataBinder.Eval(Container.DataItem,"no")%>'>

There could be lot other ways too....

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.

dparsons May 1st, 2007 06:36 AM

Personally, I do this in my SQL statements so I do not have to deal with NULL values in code.

SELECT ISNULL([column], 'No Data') as [column] FROM [table]

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========

duchemin01 September 1st, 2007 06:28 PM

hey dparsons: great, great great aproach... you've just solved my misery... ;)

==============================================

...no such things as a day at the beach..


All times are GMT -4. The time now is 04:08 PM.

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