从下拉到asp压光机的月份选择错误 [英] Disply selected month from drop down to asp calender
问题描述
朋友们,我有几个月下降,我有一个asp日历,我需要显示选定月份的日历下拉
例如:
< asp:DropDownList ID = MonthDropdownlist runat = server >
< ; asp:ListItem 文字 = 选择 值 = 0 >
< asp:ListItem 文字 = Jan 值 = 1 >
< asp:ListItem 文字 = Feb 值 = 2 >
< asp:ListItem 文本 = Mar 值 = 3 >
< asp:ListItem 文字 = 4月 值 = 4 >
< asp:ListItem 文本 = 可以 值 = 5 >
< asp:ListItem 文本 = Jun 值 = < span class =code-keyword> 6 >
< asp:ListItem 文本 = 7月 值 = 7 >
< asp:ListItem 文字 = 8月 值 = 8 >
< asp:ListItem 文本 = 9月 值 = 9 >
< span class =code-keyword>< asp:ListItem 文字 = 10月 值 = 10 >
< asp:ListItem 文本 = 11月 值 = 11 >
< span class =code-keyword>< asp:ListItem 文本 = Dec 值 = 12 >
< asp:日历 宽度 = 90% ID = JobsCalender runat = server OnDayRender = JobsCalender_DayRender >
添加前标签 - Amit [/ edit]
使用 SelectionChanged 事件日历:
void Selection_Change(对象发件人,EventArgs e)
{
// 在这里更新您的DropDownList ...
}
要更新下拉列表,使用类似这样的东西:
DropDownList1。 SelectedIndex = DropDownList1.Items.IndexOf(TheMonthInCalendarControl);
// 从日历控件中提取月份并使用它来设置下拉列表SelectedIndex
[问题上的标签说 C#所以答案是 C#(而不是 Javascript )]
干杯,
Edo
获取一个asp:日历和下面的下拉列表.........
< asp:calendar id =DateTimePickerrunat =serveronselectionchanged =DateTimePicker_SelectionChangedxmlns:asp =#unknown>
< asp:dropdownlist id =ddlCalenderrunat =serverheight =22pxwidth =260px xmlns:asp =#unknown>
< asp:listitem selected =Truevalue =>选择
并编写代码.aspx.cs页面贝娄......... ..........
protected void DateTimePicker_SelectionChanged(object sender,EventArgs e)
{
尝试
{
string month = GetMonthName(DateTimePicker.SelectedDate);
ddlCalender.SelectedItem .Text = month.ToString();
}
catch(Exception ex)
{
throw ex ;
}
}
公共静态字符串GetMonthName(DateTime givenDate)
{
var formatInfoinfo = new DateTimeFormatInfo();
string [] monthName = formatInfoinfo.MonthNames;
return monthName [givenDate.Month - 1];
}
hi friends i have a drop down with months and i have a asp calender , I need to show calender with selected month from drop down
eg:
<asp:DropDownList ID="MonthDropdownlist" runat="server">
<asp:ListItem Text="Select" Value="0">
<asp:ListItem Text="Jan" Value="1">
<asp:ListItem Text="Feb" Value="2">
<asp:ListItem Text="Mar" Value="3">
<asp:ListItem Text="Apr" Value="4">
<asp:ListItem Text="May" Value="5">
<asp:ListItem Text="Jun" Value="6">
<asp:ListItem Text="July" Value="7">
<asp:ListItem Text="Aug" Value="8">
<asp:ListItem Text="Sept" Value="9">
<asp:ListItem Text="Oct" Value="10">
<asp:ListItem Text="Nov" Value="11">
<asp:ListItem Text="Dec" Value="12">
<asp:Calendar Width="90%" ID="JobsCalender" runat="server" OnDayRender="JobsCalender_DayRender">
[edit]Pre tag added - Amit[/edit]
Use the SelectionChanged event of the calendar:
void Selection_Change(Object sender, EventArgs e) { // update your DropDownList here... }
To update the dropdownlist, use something like this:
DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(TheMonthInCalendarControl); // extract the month from your calendar control and use it to set the dropdownlist SelectedIndex
[The tag on the question said C# so the answer is in C# (rather than Javascript)]
Cheers,
Edo
Get a asp: calender and a dropdownlist like bellow.........
<asp:calendar id="DateTimePicker" runat="server" onselectionchanged="DateTimePicker_SelectionChanged" xmlns:asp="#unknown">
<asp:dropdownlist id="ddlCalender" runat="server" height="22px" width="260px" xmlns:asp="#unknown">
<asp:listitem selected="True" value="">Select
and write code .aspx.cs page bellow...................
protected void DateTimePicker_SelectionChanged(object sender, EventArgs e)
{
try
{
string month = GetMonthName(DateTimePicker.SelectedDate);
ddlCalender.SelectedItem.Text = month.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
public static string GetMonthName(DateTime givenDate)
{
var formatInfoinfo = new DateTimeFormatInfo();
string[] monthName = formatInfoinfo.MonthNames;
return monthName[givenDate.Month - 1];
}
这篇关于从下拉到asp压光机的月份选择错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!