繁体   English   中英

如何使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM