This is a migrated thread and some comments may be shown as answers.

Binding Radgrid to a Datatable containing Exponents Value

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 04 Nov 2011, 06:00 AM
Hi,

This is my first posting in this forum.

I am currently having an issue where by a DataTable returned from the Database Query 'may' contains exponents and when I attempted to Bind the table [Basic Binding]:

RadGrid.DataSource = DataTable;
RadGrid.DataBind(); // Error Generated at this code location

Please refer to attached for a simple snapshot as to data for binding that is generating the error.

I have tried to identify the exact RadGrid Events where this exception is generated but I was unable to determine the event.

Is there a way for the Radgrid to handle these values (via settings) or do I have to handle it manually in the correct Radgrid event?

Thanks.

The Exception is:

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.FormatException: Input string was not in a correct format.

   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)

   at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)

   at Telerik.Web.UI.GridDataSetHelper.Add(Object a, Object b)

   at Telerik.Web.UI.GridDataSetHelper.CalculateAggregates(DataRow SourceRow, DataRow DestRow, Int32 rowCountInGroup, GridTableView view)

   at Telerik.Web.UI.GridDataSetHelper.InsertGroupByInto(GridTableView gridTableView, DataTable DestTable, DataTable SourceTable, String RowFilter, Int32 FirstIndexInPage, Int32 LastIndexInPage, Boolean ApplyPaging, Boolean IsCustomPaging)

   at Telerik.Web.UI.GridDataSetHelper.CalcGroupByTables(GridTableView gridTableView, DataTable SourceTable, String RowFilter, Int32 FirstIndex, Int32 LastIndex, Boolean applyPaging, Boolean isCustomPaging)

   at Telerik.Web.UI.GridEnumerableFromDataView.PerformTransformation()

   at Telerik.Web.UI.GridEnumerableFromDataView.TransformEnumerable()

   at Telerik.Web.UI.GridTableView.GetEnumerator(Boolean useDataSource, GridEnumerableBase resolvedDataSource, ArrayList dataKeysArray)

   at Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource)

   at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource)

   at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)

   at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)

   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()

   at Telerik.Web.UI.GridTableView.PerformSelect()

   at Telerik.Web.UI.GridTableView.DataBind()

   at Telerik.Web.UI.RadGrid.DataBind()

   at Pages_Forecasts_StockForecastDrillDown.LoadSecurityFactors(String tDate, DataTable dt) in c:\Perforce\Acadian\Portal\MAIN\Research\web\Pages\Forecasts\StockForecastDrillDown.aspx.cs:line 986

   at Pages_Forecasts_StockForecastDrillDown.ucSecuritySelect_SelectedIndexChanged(Object sender, SecuritySearchEventArgs e) in c:\Perforce\Acadian\Portal\MAIN\Research\web\Pages\Forecasts\StockForecastDrillDown.aspx.cs:line 842

   at Controls_SecurityDropDownList.OnSecurityChanged(SecuritySearchEventArgs e) in c:\Perforce\Acadian\Portal\MAIN\Research\web\Controls\SecurityDropDownList.ascx.cs:line 40

   at Controls_SecurityDropDownList.cboSecurity_SelectedIndexChanged(Object o, RadComboBoxSelectedIndexChangedEventArgs e) in c:\Perforce\Acadian\Portal\MAIN\Research\web\Controls\SecurityDropDownList.ascx.cs:line 224

   at Telerik.Web.UI.RadComboBox.OnSelectedIndexChanged()

   at System.Web.UI.Page.RaiseChangedEvents()

   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

   --- End of inner exception stack trace ---

   at System.Web.UI.Page.HandleError(Exception e)

   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

   at System.Web.HttpContext.InvokeCancellableCallback(WaitCallback callback, Object state)

   at System.Web.UI.Page.AsyncPageBeginProcessRequest(HttpContext context, AsyncCallback callback, Object extraData)

   at ASP.pages_forecasts_stockforecastdrilldown_aspx.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object data) in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\8609db0b\e58b7a69\App_Web_stockforecastdrilldown.aspx.4393a603.ujchnqwd.0.cs:line 0

   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


2 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 09 Nov 2011, 05:24 PM
Hello Daniel,

In your particular scenario, RadGrid tries to parse the string representation of your value into a decimal. The statement that faills looks like:

decimal.Parse(a.ToString())

where a is your data value. You will get the same error if you try to parse the string "8.385503E-06" (as you have in your database):

//this generates the same error
decimal.Parse("8.385503E-06")

So, parsing strings that represent floating point values and have exponent parts is not currently supported in RadGrid.

That being said, I am not able to reproduce this exception in my tests. I created a sample database with a table containing a column of type real. I entered values in exponential notation in it. I was then able to successfully bind RadGrid to that table using an SqlDataSource control. Grouping works OK and I have correct group header and footer aggregates.

Can you share some more information on your data source as well as your RadGrid configuration that we can look at? This will help us better identify your scenario.

Greetings,
Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Daniel
Top achievements
Rank 1
answered on 28 Nov 2011, 09:59 AM
Hi Veli,

Thank you for your response.

I have managed to resolve the issue through the use of functions on the gridtemplatecolumn on the markup.

Best Regards,
Daniel

<Radgrid...>
<MasterTableView>
<Columns>
<GridTemplateColumn>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# FormatDecimal(Eval("Value"))%>'
</ItemTemplate>
</GridTemplateColumn>
..
</Columns>
</RadGrid>
 
 
CS:
public string FormatDecimal(object value)
{
   .... Other Code
       Decimal.Parse(value.ToString(), System.Globalization.NumberStyles.Any);
}
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Veli
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or