Solved

if statements within my gridview

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

627 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