in the database i have certain date as 01/01/1900.now while displaying this in the data grid along with the other columns i would like to display all the dates having value 01/01/1900 as blank.is it possible to do so?if yes then how?

Recommended Answers

All 10 Replies

Use the ItemDataBound or RowDataBound event of the datagrid. This event is fired right after the item is data bound so you can manipulate the formatting of the item based on the data. Search google : "RowDataBound Custom Formatting"

You can easily create a function and call it, like below:

<script language="vb" runat="server">
Function ChkDate(ByVal dt As String) As String
    If dt = "01/01/1900" Then
        ChkDate = ""
    Else
        ChkDate = dt
    End If
End Function
</script>

<%# ChkDate(Eval("Date")) %>

Using RowDataBound event helps seperating the markup from the code. In performans terms, they seem equal

commented: =') +5

I agree, using RowDataBound event will be better. But if it is too advanced, stick with a function. You can always do the function first to fix errors, then move onto RowDataBound.

It's all relatively easy, just look it up and you'll find it.

thanks for your suggestion but i am using the same data gridto display data from different tables.so everytime the column no of the date column does not remain same so i cannot use the RowDataBound event.any better solutions?????????

If your data is typed, then you can check the data type, if it is of DateTime, call the function if not do nothing. If your data is not typed, then you can check the data type using regular expressions. If it matches datetime format then call the function else do nothing.

Then use a function and call it when you need it!

Read like 5 posts up.

i tried the function shown above but it did not help.it gave error

and that error is...?

also try this:

<script language="vb" runat="server">
Function ChkDate(ByVal dt As String) As String
    If dt = "01/01/1900" Or dt = "1/1/1900" Then
        ChkDate = ""
    Else
        ChkDate = dt
    End If
End Function
</script>

<%# ChkDate((Eval("Date")).ToString("d")) %>

it worked.the change i needed to make was at the sql query.one sud write dbo.functionname(parameter).
thanks 4r ur help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.