using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class DataGrid_ColumnsDataFormatting : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Define SQL query
string SqlQuery = @"SELECT * FROM DataFormat";
//Get DataTable (MS Access Database)
DataTable myDataSource = DataBase.GetDataTableOleDb(SqlQuery, "~/DataGrid/DataBases/DataFormat.mdb");
//Set the data source
myDataGrid.DataSource = myDataSource;
myDataGrid.DataBind();
//Format data
string CultureValue = "en-US";
System.IFormatProvider format = new System.Globalization.CultureInfo(CultureValue, true);
myDataGrid.Columns["DateTime"].FormatProvider = format;
myDataGrid.Columns["DateTime"].FormatType = typeof(System.DateTime);
myDataGrid.Columns["DateTime"].FormatString = "D";
myDataGrid.Columns["Currency"].FormatProvider = format;
myDataGrid.Columns["Currency"].FormatType = typeof(System.Decimal);
myDataGrid.Columns["Currency"].FormatString = "C";
myDataGrid.Columns["Number"].FormatProvider = format;
myDataGrid.Columns["Number"].FormatType = typeof(System.Double);
myDataGrid.Columns["Number"].FormatString = "N";
}
}
|