Help! Gridview not formatting with DataFormatString

B

Burt

My GridView won't format! See code below, I've got HtmlEncode turned
off, and still nothing works...the GV just has the raw data. Pulling
my hair out over this. Could it be because I'm building the source
(DataTable) dynamically? Thanks for any help. Using .Net 2.0, VS 2005,
VB - Burt


<asp:GridView id="dataGridResults" runat=server
AutoGenerateColumns="False">
<Columns>

<asp:BoundField DataField="Gross Return" HtmlEncode="false"
HeaderText="Gross Return" DataFormatString="{0:#,##0.00}"/> </Columns>
</asp:gridview>


Dim dt As New DataTable
dt.Columns.Add("Gross Return")

For Each Y As Year In u.Years
dr = dt.NewRow()
dr("Gross Return") = py.EndValue
..
..
..

dataGridResults.DataSource = dt
dataGridResults.DataBind()
 
A

Angel

It could be the mixing of the declarative and code that's confusing things.

Try this instead in code.

Dim bf as boundfield = new boundfield
bf.HtmlEncode = False
bf.DataFormatString ="{0: #,##0.00}"
bf.HeaderText="Unit Price"
bf.DataField = "UnitPrice"
GridView1.Columns.Add(bf)

I am going to try your example see if I can get it to work
 
A

Angel

I think that I got it.

In my opinion there is a bug in format. It will not format to specification
if the data type is already a string

So, when you define column do as follows

dt.Columns.Add("Gross Return", GetType(Decimal))

or whatever as long as is not string. I mimic your problem and had the same
results and this fixed it.

Good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top