如何在选中时设置下拉菜单然后第一个下拉菜单 [英] how to set dropdown when selected cannot be smaler then the first dropdown

查看:107
本文介绍了如何在选中时设置下拉菜单然后第一个下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我创建了两个下拉菜单

从年份到年份

如果用户选择从1955年到年份1945年还不行?

i我现在正在使用此代码



Hi!
I have created two dropdowns
From year and To Year
if the user select From year 1955 and to year to 1945 thats not ok?
i am using this code right now

int startYear = 1950;
            var data = Enumerable.Range(startYear, DateTime.Now.Year - (startYear - 1));
                DpListFranArUtbildning.DataSource = data;
                DpListFranArUtbildning.DataBind();
                DpListFranArUtbildning.Items.Insert(0, "- Select -");

                DpListTillArUtbildning.DataSource = data;
                DpListTillArUtbildning.DataBind();
                DpListTillArUtbildning.Items.Insert(0, "- Select -");





所以我想这样做,用户只能花更多年的时间他从1955年到1955年以及从1955年开始选择或同年的第一年和>

但不是从2000年到1995年



so i would like to make so the user can only can take higher years from the first he select or the same year like from 1955 to 1955 and also from 1955 and >
but not from 2000 to 1995

推荐答案

你可以通过在运行时插入第二个下拉列表中的年份来实现这一点。



例如..如果我选择1955 ..那么在运行时......从1955年开始(1955年+限制)...在第二次下拉中..!



这样用户就不会有误......



但页面会刷新..我们正在调用服务器边码!



为此,你可以用javascript..at客户端做同样的事情!
You can do this by inserting the years in second dropdown at runtime..

eg.. if i chose 1955..then at runtime..insert years from 1955 to (1955+limit)..in second dropdown..!

This way user can''t be mistaken..

But the page will be refreshed..as we are calling server side code!

For this, you can do the same with javascript..at client end!


为你提供如何用最简单的例子解决这个问题。你可以得到概述并实现它。



Aspx页面:

Providing you how to resolve this with simplest example possible.You can get overview and implement it.

Aspx page:
<asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem Text="1995" Selected="True" Value="1995" />
        <asp:ListItem Text="1996" Value="1996" />
    </asp:DropDownList>
    <asp:DropDownList ID="DropDownList2" runat="server"  AutoPostBack="true"

        onselectedindexchanged="DropDownList2_SelectedIndexChanged">
        <asp:ListItem Text="1995" Selected="True" Value="1995" />
        <asp:ListItem Text="1996" Value="1996" />
        <asp:ListItem Text="1997" Value="1997" />
        <asp:ListItem Text="1998" Value="1998" />
    </asp:DropDownList>
    <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>



代码背后:




Code behind:

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Convert.ToInt32(DropDownList2.SelectedValue) < Convert.ToInt32(DropDownList1.SelectedValue))
            {
                Label3.Text = "error";

            }
            else
            {
                Label3.Text = "ok";
            }
        }



您可以看到,在更改第二个下拉值时,代码会检查这两个值,如果第二个值较低然后标签显示文本错误,否则显示确定。


You can see that on changing the value of second drop down the code checks the two values,if the second one is lower then label shows text error,otherwise it displays ok.


这篇关于如何在选中时设置下拉菜单然后第一个下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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