Solved

if statements within my gridview

Posted on 2011-03-03
3
445 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

22 Experts available now in Live!

Get 1:1 Help Now