473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Formatting Gridview

Hi! I have a problem which I think has a simple solution, but I can't
figure out why it's not working.

Some background...
I'm populating a GridView with info from an Access database like this:

Public Sub LoadGrid()
Dim ConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;
DataSource=C:\DATABASE\NCP.mdb;"

Dim NCPCon As New SDO.OleDbConnection(ConnectionString)
Dim SQL As String = "SELECT * FROM TEST1_IN;"

Dim cmd As New SDO.OleDbCommand(SQL, NCPCon)
Dim adapter As New SDO.OleDbDataAdapter(cmd)
Dim dsTEST As New DataSet()

NCPCon.Open()
adapter.Fill(dsTEST, "TEST1")
NCPCon.Close()

GridView1.DataSource = dsTEST.Tables("TEST1")
GridView1.DataBind()
Me.DataBind()
End Sub

Then I try to format the data by using this in the RowDataBound event:

If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(1).Text = Format(e.Row.Cells(1).Text,
"#,###.00")
End if

The problem is that when the table is rendered this generates a column
full of #,###.00 instead of the actual values like this:

Name Salary
Lucy #,###.00
John #,###.00
Mark #,###.00
etc...

why could it be that the format function does not work?

Thanks for your help!

Dec 23 '06 #1
1 977
I tried this and it worked...

e.Row.Cells(4).Text = String.Format("{0:#,###}", e.Row.Cells(4).Text *
1)
e.Row.Cells(4).HorizontalAlign = HorizontalAlign.Right

Guess it wasn't working because it was trying to format a value that
was already text. This also works:

e.Row.Cells(4).Text = Format(e.Row.Cells(4).Text * 1, "#,###")

is there a more elagant way of doing this?

Dec 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: washoetech | last post by:
I have a gridview control. In this grid view there is a column for the price of an item. Some of the prices have a dollar sign in front of it and some dont. How do I get rid of the dollar sign...
1
by: euan | last post by:
HI Guys, I have bee using conditional formatting in the datagrid recently and I am moving over to framework 2.0 and noticed the datagrid has been replaced by the gridview. So, I would like to do...
4
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I...
3
by: Simon Harvey | last post by:
Hi all, I'm having problems getting my date to format. Someone told me that with the GridView, you need to use a TemplateColumn and not a BoundColumn when displaying dates. Given that, can...
3
by: CSharpguy | last post by:
I'm trying to format the GridView on my web form and its not working. for money I have {0:C} and for date fields, I have {0:d} and the format isn't changing, what else do I need to do to get the...
4
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
1
by: AmitKu | last post by:
I've got the Gridview going at full speed, and I've enabled editing, but when I click on the "edit" button, this ugly editing UI comes up. Well it's not ugly, but it's not great either. How do I...
2
by: pgonzo | last post by:
In my initial tests with the GridView control, I cannot understand why the DataFormatString attribute has no affect on the column formatting. The 'creation_date' field is being reported as "3/30/02...
0
by: Adam Sandler | last post by:
Hello, My codebehind builds a GridView at runtime and shovels the data off as a part of a callback... Dim returnstring As String = String.Empty Dim gv As New GridView gv.DataSource = ds...
2
by: tomh2099 | last post by:
Hi, Hi, I have an ASP.NET 2005 application (using VB) with a GridView control that needs to have the last 5 or 6 rows in Bold or maybe some other special formatting. Most of the rows show...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.