Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

if statements within my gridview

Posted on 2011-03-03
3
Medium Priority
?
459 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 1000 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 1000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

963 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