Computing.Net > Forums > Web Development > ASP.net DataGrid Display!!! Help!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

ASP.net DataGrid Display!!! Help!

Reply to Message Icon

Name: Jay_0901
Date: March 22, 2005 at 10:22:07 Pacific
OS: Win XP sp 2
CPU/Ram: P4 3.0Ghz/ 512 MB
Comment:

Hi I am trying to read from an excel file to my asp.net pages. Everything displays fines except the column the has decimal values in it. In my excel files I am restricting the Cell format to only show 2 decimal but some how when I read this in to my asp page it display all the decimals... I want to truncte the values to 2 decimals only can some one guide me how to do this...the code I using to display an excel file in asp is as follows:
private void Page_Load(object sender, System.EventArgs e)
{
DataSet myDataSet = new DataSet();
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\exceltest.xls;" + "Extended Properties=\"Excel 8.0;\"";
OleDbDataAdapter myData = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
myData.TableMappings.Add("Table", "ExcelTest");
myData.Fill(myDataSet);
dgrdSample.DataSource = myDataSet.Tables[0].DefaultView;
dgrdSample.DataBind();
}

how can I trucate the output to 2 decimals...I am using C# to code... Will appreciate any help...Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: SN
Date: March 24, 2005 at 06:17:29 Pacific
Reply:

I can think of a few ways, but probably the best is using the DataBinder.eval method.

Format Data and Handle Null Values in a DataGrid Web Control

Other options would be to loop through the dataset and round each value yourself, put in another column in the data table with an expression to round the source column's values, or round at item binding by handling the DataGrid.OnItemDataBound event.

-SN


0

Response Number 2
Name: Jay_0901
Date: March 25, 2005 at 09:05:41 Pacific
Reply:

Sorry about the double posting... I used the Gaurish's method and it work fine
(("SELECT ROUND (Column1,2) FROM [Sheet1$]", strConn);
but now the only problem I have is... after rounding the values in this column the trailing zeros get cut off(1.50 changes to 1.5)...I need to keep the trailing zeros as the represent price...if can help me on how I can still display the trailing zeros that would be a lot of help...thanks


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Browsing CVS Repositories How to check external URL...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: ASP.net DataGrid Display!!! Help!

ASP.net DataGrid Display!!!Help! www.computing.net/answers/webdevel/aspnet-datagrid-displayhelp/1603.html

checkbox within datagrid (ASP.NET) www.computing.net/answers/webdevel/checkbox-within-datagrid-aspnet/828.html

Date pop-up box in ASP.NET www.computing.net/answers/webdevel/date-popup-box-in-aspnet/833.html