1

I have a gridview column which displays two date values. I would like to hide the second value in cases where the two dates are the same.

<asp:TemplateField HeaderText="Date Range">
    <ItemTemplate>
        <%# string.Format("{0:dd MMM yyyy} {1:dd MMM yyyy}", Eval("From_Date") ,Eval("To_Date"))%>
    </ItemTemplate>
</asp:TemplateField>
2
<asp:TemplateField HeaderText="Date Range">
    <ItemTemplate>
        <%# string.Format("{0:dd MMM yyyy}", Eval("From_Date")).Equals(string.Format("{0:dd MMM yyyy}" ,Eval("To_Date")))? string.Format("{0:dd MMM yyyy}", Eval("From_Date")) : string.Format("{0:dd MMM yyyy} {1:dd MMM yyyy}", Eval("From_Date") ,Eval("To_Date"))%>
    </ItemTemplate>
</asp:TemplateField>

Not sure I got all the parentesis right, but something like this might do the trick!

  • Thanks Robert. There were just some missing closing brackets the rest seems good. Although I get this error message : Cannot implicitly convert type string to bool. I know what the error means, but don't really understand what the problem is. – Pieter Du Toit Nov 15 '13 at 7:56
  • Added the missing parentesis, and citation chars – Robert Lindgren Nov 15 '13 at 7:59
  • Glad to help you out! – Robert Lindgren Nov 15 '13 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.