?
Solved

Set myDataColumn.DataType in Gridview

Posted on 2010-11-22
5
Medium Priority
?
684 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

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

Author Comment

by:mgabr123
ID: 34191416
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
ID: 34191434
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
ID: 34191500
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 2000 total points
ID: 34191654
Ah, sorry, wasn't paying attention :)

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

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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 video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

762 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