User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,520 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,814 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 4012 | Replies: 1
Reply
Join Date: Aug 2007
Location: Somewhere between heaven and hell
Posts: 112
Reputation: Kusno is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster

Format GridView Columns

  #1  
Oct 4th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Format GridView Columns

  #2  
Oct 6th, 2007
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.
Last edited by SheSaidImaPregy : Oct 6th, 2007 at 6:09 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 4:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC