使用asp.net中的下拉列表控制日历 [英] calendar control using dropdown in asp.net

查看:175
本文介绍了使用asp.net中的下拉列表控制日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请让我通过下拉列表了解日历控制的月份和年份详情

please let me give an idea regarding calendar control using dropdown list for month and year details

推荐答案





这里我提供了生成带有下拉列表控件的日历的链接



http://www.codeproject.com/KB/scripting/JavaScriptCalendar.aspx



我希望这个链接有帮助你了解日历控制细节





我在下拉列表中尝试了一些生成月份的代码



Hi,

Here I''m providing link for generating calender with dropdownlist controls

http://www.codeproject.com/KB/scripting/JavaScriptCalendar.aspx

I hope this links helps you to understand calender control details


And I tried some code for generating months in dropdown list

<form id="form1" runat="server">
<div>
  <table>
    <tr>
      <td>Year :
          <asp:DropDownList ID="ddlyear" runat="server">

      </td>
      <td>Month :
          <asp:DropDownList ID="ddlmonth" runat="server" AutoPostBack="True"
              onselectedindexchanged="ddlmonth_SelectedIndexChanged">

      </td>
      <td>Date :
          <asp:DropDownList ID="ddldate" runat="server">

      </td>
    </tr>
  </table>
</div>
</form>





和文件背后的代码包含以下代码





And the code behind file contains following code

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {

        for (int i = 1; i <= 12; i++)
        {
             System.Globalization .DateTimeFormatInfo nm=new System.Globalization.DateTimeFormatInfo ();
             ddlmonth.Items.Add (new ListItem (nm.GetMonthName(i).ToString (),i.ToString ()));

        }
        for (int i = 1900; i <= System.DateTime.Now.Year; i++)
        {


            ddlyear.Items.Add (new ListItem( i.ToString (),i.ToString ()));

        }

    }
}
protected void ddlmonth_SelectedIndexChanged(object sender, EventArgs e)
{
    ddldate.Items.Clear();
    for (int i = 1; i <= System.DateTime.DaysInMonth(int.Parse(ddlyear.SelectedValue), int.Parse(ddlmonth.SelectedValue)); i++)
    {
          ddldate .Items.Add (new ListItem (i.ToString (),i.ToString ()));
    }

}





在上面的代码中,我填写的日期基于用户选择的月份。



如果您可以使用jquery,则可以通过异步请求动态填充。

或使用Ajax更新面板< br $> b $ b

所有最佳



In the above code I filled days based on month selected by user.

If you can use jquery it is easy fill dynamically with asynchronous requests.
or use Ajax update panels also

All the Best


这篇关于使用asp.net中的下拉列表控制日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆