Computing.Net > Forums > Programming > ASP.net DataGrid Display!!!

ASP.net DataGrid Display!!!

Reply to Message Icon

Original Message
Name: Jay_0901
Date: March 22, 2005 at 09:07:52 Pacific
Subject: ASP.net DataGrid Display!!!
OS: Win XP SP 2
CPU/Ram: P4 3.0 Ghz/ 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


Report Offensive Message For Removal

Response Number 1
Name: bugsvoid
Date: March 23, 2005 at 02:59:50 Pacific
Subject: ASP.net DataGrid Display!!!
Reply: (edit)

The problem is not with the grid but with the query. Try the select Query as :

'SELECT ROUND(<<COLUMN_NAME>>,2) FROM .... WHERE ....'

Here 2 is the decimal precision (2 digits after the decimal pt).

Regards,
Gaurish



Report Offensive Follow Up For Removal

Response Number 2
Name: Jay_0901
Date: March 23, 2005 at 13:34:09 Pacific
Subject: ASP.net DataGrid Display!!!
Reply: (edit)

Thanks Gaurish....That was a lot of help....I just had one more question if you could help me out....
'SELECT ROUND(<<COLUMN_NAME>>,2) FROM .... WHERE ....' with this I am only able to select one Column, do you happen to know the syntax to either do all columns from the sheet or do more then one column...Thanks



Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: ASP.net DataGrid Display!!!

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software