Solved

if statements within my gridview

Posted on 2011-03-03
3
443 Views
Last Modified: 2012-05-11
Hi,

I have the following column in my gridview:
<asp:TemplateField HeaderText="Date Resolved">    
                <ItemTemplate>                    
                    <asp:label ID="lblResolvedDate" runat="Server" text='<%#DataBinder.Eval(Container.DataItem,"DateResolved","{0 :dd/MM/yyyy}")%>' ></asp:label>                    
                </ItemTemplate>                                
            </asp:TemplateField>

I want an if statement within it to say if the date is "01-jan-1900" then display "-" rather than the date value

How do I do this?
0
Comment
Question by:scm0sml
3 Comments
 

Author Comment

by:scm0sml
ID: 35027851
Just to note I dont want to do this in the code behind, am sure I can do it this way just not sure of the syntax.
0
 
LVL 22

Accepted Solution

by:
Mrunal earned 250 total points
ID: 35034366
try this:

<%# Convert.ToDateTime(DataBinder.Eval(Container.DataItem,"DateResolved")) == Convert.ToDateTime("01-jan-1900") ? "-" : DataBinder.Eval("DateResolved","{0:d}") %>

Note: please check the format also.

http://www.beansoftware.com/ASP.NET-Tutorials/Conditional-Values-Styles-GridView.aspx
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
ID: 35035469
If its VB.NET, use the IIF function

<asp:label ID="lblResolvedDate" runat="Server" text='<%#IIF(DataBinder.Eval(Container.DataItem,"DateResolved","{0 :dd/MM/yyyy}")="01-jan-1900", "-", DataBinder.Eval(Container.DataItem,"DateResolved","{0 :dd/MM/yyyy}"))%>' ></asp:label>  
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Check if number is currency 15 29
Different Delete Messages 7 19
SQL best practice question 3 14
Close word object 13 21
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now