[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 688
  • Last Modified:

Set myDataColumn.DataType in Gridview

I was just wondeirng if anyone could explain how to change the  DataType associated with a gridview in C#?  The gridview is bound to a sqldatasource, however, one field that I want to format (Amount) as a currency is being automatically set as an integer column.  So when I try to reformat the mydatarowview['Amount'] in the Rowcreated event I get a failure when I go to write the updated value as its now a string.

If there is a better way to go about this I would love to hear it as I am just coming over from years of PHP so ASP is still fairly new to me.  I know how to go about this with SQL if need be but I really wanted to get it sorted out on my ASP page.

TIA
0
mgabr123
Asked:
mgabr123
  • 3
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
can you post what you are doing at the moment that is causing the problem?
0
 
mgabr123Author Commented:
Double testdouble = Convert.ToDouble(myDataRowView["Amount"].ToString());
 String teststring = String.Format("{0:C}", testdouble);
 myDataRowView["Amount"] = teststring;

Open in new window


I basically am running into problems on the third line.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Ah ok. If you are doing that then you can simply parse the value back to double to store:

myDataRowView["Amount"] = double.Parse(teststring);

Open in new window

0
 
mgabr123Author Commented:
Even with that added it still threw an error:

"Input string was not in a correct format"
Double testdouble = Convert.ToDouble(myDataRowView["Amount"].ToString());
                    String teststring = String.Format("{0:C}", testdouble);
                    myDataRowView["Amount"] = double.Parse(teststring);

Open in new window

0
 
Carl TawnSystems and Integration DeveloperCommented:
Ah, sorry, wasn't paying attention :)

Try:
myDateRowView["Amount"] = double.Parse(teststring, System.Globalization.NumberStyles.AllowCurrencySymbol);

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now