如何在文本框中显示所选的日历值?我想在asp.net或C#中找到答案。
答案 0 :(得分:6)
对于WinForms(我使用过DateTimePicker
),您可以处理ValueChanged
事件......
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
textBox1.Text = dateTimePicker1.Text;
}
对于ASP.NET控件(我使用了Calendar
控件),您可以处理SelectionChanged
事件......
[Markup]
<asp:Calendar ID="Calendar1" runat="server"
onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
[CodeBehind]
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
}
希望有所帮助:)
答案 1 :(得分:1)
textbox.Text = yourCalendar.SelectedDate
更多详情:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.selecteddate.aspx