Solved

Set myDataColumn.DataType in Gridview

Posted on 2010-11-22
5
667 Views
Last Modified: 2012-06-22
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
Comment
Question by:mgabr123
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
can you post what you are doing at the moment that is causing the problem?
0
 

Author Comment

by:mgabr123
Comment Utility
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
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
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
 

Author Comment

by:mgabr123
Comment Utility
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
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
Comment Utility
Ah, sorry, wasn't paying attention :)

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

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now