Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
More grid woes
Message
From
06/07/2005 11:33:04
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
05/07/2005 11:14:42
General information
Forum:
ASP.NET
Category:
WebForms
Title:
Environment versions
Environment:
ASP.NET
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01029008
Message ID:
01029511
Views:
11
This message has been marked as a message which has helped to the initial question of the thread.
Alex,
Yeah not only Iformatprovider but .Net help is as clear as mud:)
Try:
 dr[1]	= double.Parse(sValue, NumberStyles.Currency);
PS: Add System.Globalization to using directives.
Cetin


>Still battling with the ASP.NET GridView control.
>
>The problem this time is IFormatProvider and my lack of understanding of it.
>
>Say I have a simple 2-column grid I want to bind to a DataTable at runtime. The data comes from another table where I have to extract info depending on some conditions.
>
>Simplified:
>
>string sDescrip="";
>string sValue="";
>DataTable dt = new DataTable();
>DataRow dr;
>
>// add two columns
>dt.Columns.Add(new DataColumn("Description", typeof(String)));
>dt.Columns.Add(new DataColumn("Value", typeof(double)));
>// I have a foreach() loop here to work through another DataTable
>// and decide if want want to extract info from it for the grid (complex reasons)
>// say the condition is: iWantItCondition (for each item)
>if (iWantItCondition==true)
>{
>// oRow[oColumn.Columname] is the current row in the current column in the source table
>
>  // we move here to a column to get decription -- [code snipped]
>  sDescrip=oRow[oColumn.ColumnName].ToString();
>
>  // we move here to another column to get value -- [code snipped]
>  sValue=oRow[oColumn.ColumnName].ToString();
>  dr = dt.NewRow();
>  dr[0] = sDescrip;
>
>  // here's the problem
>  // I want to format the string depending on what it is (sometimes a percentage, sometimes currency)
>  // for example's simplicity let's deal only with Currency here
>
>  // this line doesn't work:
>  // Runtime error: "Input string was not in a correct format.
>  //    Couldn't store <$134.00> in Value Column. Expected type is Double."
>  dr[1] = double.Parse(sValue).ToString("C")
>
>  ////// debug:  this line works and it shows onscreen as $134.00 correctly
>  Response.Write(sValue + ": " + double.Parse(sValue).ToString("C") + "<br>");
>  ////// debug
>
>  dt.Rows.Add(dr);
>}
>
>// after done building the datarows, bind them to a grid
>this.GridViewOthers.DataSource = dt;
>this.GridViewOthers.DataBind();
>
>Why does the Response.Write work fine with proper Currency formatting, but the assignment to data row 2nd column dr[1] does not? dr[1] is defined as a double. The formatted value I want to store is parsed as a double.
>
>Do I have to save everything as a string to get formatting? The help samples for IFormatProvider are as clear as mud.
>
>Any ideas appreciated.
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform