![](/img/trans.png)
[英]Display Current Date Time in TextBox using MaskedEditExtender in asp.net
[英]How to show the Current date in textBox using Asp.net
誰能告訴我如何以這種格式(dd-mm-yyyy)
打印current data
?
我正在使用此命令,但不起作用:
protected void TextBoxStartDate_TextChanged(object sender, EventArgs e)
{
TextBoxStartDate.Text = DateTime.Now.ToString();
// TextBoxStartDate.Text = DateTime.Now();
}
我想用current date
autofill
文本框
我如何以這種格式(dd-mm-yyyy)打印當前數據
較低的毫米表示分鍾.. !!
您可以使用以下格式:
DateTime.Now.ToString("dd-MM-yyyy");
像這樣更改代碼:
protected void TextBoxStartDate_TextChanged(object sender, EventArgs e)
{
TextBoxStartDate.Text = DateTime.Now.ToString("dd-MM-yyyy");
// TextBoxStartDate.Text = DateTime.Now();
}
把這個TextBoxStartDate.Text = DateTime.Now.ToString();
在PageLoad
protected void Page_Load(object sender, System.EventArgs e)
{
TextBoxStartDate.Text = DateTime.Now.ToString();
}
這是我的ASP.cs代碼:
<asp:TextBox ID="TextBoxStartDate" runat="server" ontextchanged="TextBoxStartDate_TextChanged" Width="150px" Height="16px" ></asp:TextBox>
您可以在頁面上加載事件。
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = System.DateTime.Now.ToShortDateString();
}
您可以將其寫在Page_Load
事件上以獲取當前日期時間
該守則將是:
您還必須在代碼中包含名稱空間,
aspx和cs:-
<asp:TextBox ID="TextBoxStartDate" runat="server" OnTextChanged="TextBoxStartDate_TextChanged" Width="150px" Height="16px" ></asp:TextBox>
protected void Page_Load(object sender, EventArgs e)
{
TextBoxStartDate.Text = DateTime.Now.ToString();
}
同樣根據您的代碼,您需要在代碼隱藏中添加onTextChanged
事件
protected void TextBoxStartDate_TextChanged(object sender, EventArgs e)
{
//do something here
}
UPDATE
加載頁面時,您會在文本框中看到類似以下的內容
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.