Very often we are required to display date and money values on the webpages. In the SQL Server database, the date is stored as SQLDBType.Datetime and the currency values are stored as SBLDBType.Money.
In the C# code, the SQLDBType.Datetime should be converted to System.DateTime and SBLDBType.Money to System.decimal:
Datetime d = Convert.ToDateTime( SBLDBType.DateTime variable);
decimal m = Convert.ToDecimal( SBLDBType.Money variable);
In the Source page, these values can be displayed as:
<%# DataBinder.Eval(Container.DateItem, “Money”, “{0:c}” %> //here Money is column name
<%# DataBinder.Eval(Container.DateItem, “date”, “{0:d}” %> //here date is column name
provided the values are coming from database.
In the code-behind, these values can be defined as:
label1.Text = String.Format(“{0:c}”, SQLmoneyVariable)
label2.Text = String.Format(“{0:d}”, SQLdateVariable)
This will cause the labels to display money and date values on the webpage. String.Format is used to return the date and currency values as string in the required format.