如何在下拉列表中禁用过去的天/月 [英] How Do I Disable Past Days/Months In A Dropdownlist

查看:59
本文介绍了如何在下拉列表中禁用过去的天/月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经拿了三个下拉列表,分别是年份,月份,日期。我在隐藏模式下保留了月份和日期下拉菜单,当我选择年份时,月份下拉列表会显示并且像 - 明智的日期下拉。我的查询是,我想隐藏过去的月份和日期,我应该可以选择未来的月份和日期。请通过一些指导。



aspx.cs代码: -



I have taken three drop-down lists namely Year,Month,Date.I have kept the month and date drop-down in hidden mode,when i select the year,then the month drop-down will show up and like-wise the date drop-down.My query is,i want to hide past month and date which have gone and i should be able to select on the months and dates which are to come in the future. Please through some guidance.

aspx.cs code :-

<form id="form1" runat="server">
        <div>
            <br />
           <fieldset style="width:460px">
    <legend>Select Date</legend>
               <asp:Label ID="Label1" runat="server" Text="Year"></asp:Label>
     <asp:DropDownList ID="ddlYear" runat="server" AutoPostBack="True" Visible="True"

            onselectedindexchanged="ddlYear_SelectedIndexChanged" ></asp:DropDownList>

               <asp:Label ID="Label2" runat="server" Text="Month" Visible="false"></asp:Label>
                <asp:DropDownList ID="ddlMonth" runat="server" AutoPostBack="True" Visible="false"

            onselectedindexchanged="ddlMonth_SelectedIndexChanged">
        </asp:DropDownList>
            <asp:Label ID="Label3" runat="server" Text="Date" Visible="false"></asp:Label>
    <asp:DropDownList ID="ddlDate" runat="server" Visible="false" OnSelectedIndexChanged="ddlDate_SelectedIndexChanged">
        </asp:DropDownList>
    </fieldset>
        </div>
    </form>





aspx代码: -





aspx code :-

protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ddlYear.Items.Insert(0, new ListItem("Select a Year", "1"));
                for (int i = 2015; i <= 2020; i++)
                {
                    ddlYear.Items.Add(i.ToString());
                }

                ddlMonth.Items.Insert(0, new ListItem("Select a Month", "1"));
                var months = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames;
                for (int i = 1; i < 13; i++)
                {
                    ddlMonth.Items.Add(new System.Web.UI.WebControls.ListItem(DateTimeFormatInfo.CurrentInfo.GetMonthName(i), i.ToString()));
                    //ddlMonth.Items.Add(i.ToString());
                }

                FillDates();
            }
        }
        public void FillDates()
        {
            ddlDate.Items.Clear();
            ddlDate.Items.Insert(0, new ListItem("Select a Date", "1"));
            int noofdays = DateTime.DaysInMonth(Convert.ToInt32(ddlYear.SelectedValue), Convert.ToInt32(ddlMonth.SelectedValue));
            for (int i = 1; i <= noofdays; i++)
            {
                ddlDate.Items.Add(i.ToString());
            }

        }
        protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillDates();
            Label2.Visible = true;
            ddlMonth.Visible = true;
        }
        protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillDates();
            Label3.Visible = true;
            ddlDate.Visible = true;
        }
        protected void ddlDate_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillDates();
        }
    }

推荐答案

我建​​议您使用日历控件。 ASP.NET AjaxControlToolkit jQuery



这会给你这些功能快速简单的属性或事件。请在 Google Bing 中搜索以上任何内容并参阅示例。
I would suggest you to use a Calendar Control. Either ASP.NET AjaxControlToolkit or jQuery.

That would give you these functionalities with quick easy properties or events. Please search any of the above in Google or Bing and refer the examples.


这篇关于如何在下拉列表中禁用过去的天/月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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