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>
0

1 Answer 1

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!

3
  • 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. Commented Nov 15, 2013 at 7:56
  • Added the missing parentesis, and citation chars Commented Nov 15, 2013 at 7:59
  • Glad to help you out! Commented Nov 15, 2013 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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