how to display the selected calendar value on a text box? i want the help in asp.net or c#
A:
textbox.Text = yourCalendar.SelectedDate
More details : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.selecteddate.aspx
Amadeus45
2009-07-13 05:51:39
This would give a "Cannot implicitly convert type 'System.DateTime' to 'string'" - you need to convert the SelectedDate value to a string to display it in the textbox.
Chalkey
2009-07-13 07:28:12
+3
A:
For the WinForms (I have used DateTimePicker
) you can handle the ValueChanged
event...
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
textBox1.Text = dateTimePicker1.Text;
}
For an ASP.NET control (I have used the Calendar
control) you can handle the SelectionChanged
event...
[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();
}
Hope it helps :)
Chalkey
2009-07-13 07:24:17