Example of String.Format
How to use with Date
D_O_B=12/04/2013 11:22:33String.Format("{0:d}",Eval("D_O_B"))
<asp:TextBox ID="TextBox8" Text='<%#String.Format("{0:d}",Eval("D_O_B")) %>' Width="80px" runat="server"></asp:TextBox>
output : 12/04/2013
How to use with Time
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = string.Format("{0:t}", DateTime.Now);
}
output : 4:15 PM
============================================================
Put the double Zero after the Point(.);int chek=2525;String.Format("{0:00}",chek)
output : 2525.00
===================================================
Add The Double Zero After Point
label76.Text=string.Format("{0:N2}",Math.Round(Convert.ToDouble(label76.Text),0));
Output: 125.00
================================================================
Put the comma( , ) between number
int iii=25252252;string.Format("{0:,###,###,###,##0.00}", iii);
int iii = Convert.ToInt32(dataGridView1.Rows[b].Cells[1].Value.ToString());
string ssss = string.Format("{0:,###,###,###,##0.00}", iii);
output : 25,252,252.00
======================================================
Another Solution
Aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true"
ontextchanged="TextBox1_TextChanged" ></asp:TextBox>
<asp:Image ID="Image1" runat="server" ImageUrl="~/cal.png" Width="20px" Height="25px" />
<asp:CalendarExtender ID="CalendarExtender1" PopupButtonID="Image1" Format="MM/dd/yyyy"TargetControlID="TextBox1" runat="server">
</asp:CalendarExtender>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
<br /><br /><br />
<asp:label ID="Label1" runat="server" text="Label"></asp:label><br /><br /><br />
<asp:button ID="Button1" runat="server" text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
Aspx.cs page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = string.Format("{0:dd/MM/yy}", DateTime.Now);
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
TextBox2.Text = TextBox1.Text;
DateTime st = Convert.ToDateTime(TextBox1.Text);
string sss = string.Format("{0:dd/MM/yyyy}", st);
TextBox1.Text = sss;
}
}
No comments:
Post a Comment