Dear all .Netters,

How do i format gridview columns
to this format :

=> 9,000,000.00
=> 2007-10-05

I tried like this :

DataFormatString="{0:N2}"
DataFormatString="{0:yyyy-MM-dd}"
DataFormatString="{0:N4}"

but not worked.

Current, if format the columns in Rowdatabound events, like this :

Protected Sub GVArticle_RowdataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GVFunding.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If IsDate(e.Row.Cells(2).Text.Trim) = True Then
e.Row.Cells(2).Text = SetDateValue(CDate(e.Row.Cells(2).Text.ToString.Trim))
End If
If IsDate(e.Row.Cells(4).Text.Trim) = True Then
e.Row.Cells(4).Text = SetDateValue(CDate(e.Row.Cells(4).Text.ToString.Trim))
End If
If IsDate(e.Row.Cells(5).Text.Trim) = True Then
e.Row.Cells(5).Text = SetDateValue(CDate(e.Row.Cells(5).Text.ToString.Trim))
End If
If IsNumeric(e.Row.Cells(9).Text.Trim) = True Then
e.Row.Cells(9).Text = FormatNumber(e.Row.Cells(9).Text.ToString.Trim, 2, TriState.True)
End If
End If
End Sub

Thanks and Regards

Kusno

For your numbers, do this:

FormatNumber(yourstring,2)
Explanation:
FormatNumber(yourstringtoformat,numberofdecimalplaces)

For your dates, do this:
String.Format("{0:yyyy-MM-dd}",yourstringtoformat)

they will give you the desired outcome you are after.

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.