Solved

if statements within my gridview

Posted on 2011-03-03
3
456 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

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 …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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