Specify Format String For Auto-Generated Datagrid Column?

  • Thread starter Thread starter Joey Powell
  • Start date Start date
J

Joey Powell

Is it possible to specify a format string for one or more
auto-generated datagrid columns? If so, could someone post an example?
More specifically, I am interested in taking output like 27.0800000
and turning it into 27.08

I have also tried doing this with the underlying SQL statement, but I
can't get it to work that way, either.
 
Hi Joey,

Thank you for using MSDN Newsgroup. I am Luke and I am review this issue
currently. From your description, you want to format the output in a
datagrid, for example, from 27.0800000 to 27.08. The data is retrieve from
a database.

Regarding the question, if the database is SQL server, I think the easiest
way is doing with the underlying SQL statement, for example:

select CONVERT(decimal(15,2), DecColumn) as DecimalField from Table1

As you the Convert function in SQL server can format the decimal column
with 2 bits scale. We only need to modify the SelectCommand of the
DataAdapter like this.

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Im running into the a very similar situation.

The only difference is that my data does not come from any database
whatsoever. In fact it comes from a variety of files the user can upload, it
is then stored in a collection of objects I designed and finally displayed
in a datagrid. Is there a way to format data in this scenario?

Thanks

Juan Ramon
 
Back
Top