禁用/被选中后,在下拉菜单中删除值 [英] Disable/remove value in dropdown menu after being selected

查看:124
本文介绍了禁用/被选中后,在下拉菜单中删除值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只想问u人的帮助。我有我的abc.aspx页面此下拉菜单。在那里,用户会选择一个月并在提供的文本框中输入的费用和价格。它将被保存在会话:

Just wanna ask u guys for help. I have this dropdown menu in my abc.aspx page. There, user will choose month and enter the expenses and prices in the textbox provided. It will be saved in session :

session["month"]= dropdownlist1.selectedvalue;
session["expense1"] - textbox1.text;
session["price1"] - textbox2.text;
server.transfer ("sdf.aspx");

在下一页中,输入​​的数据将在标签中查看:

In the next page, the entered data will be viewed in label:

Label1.Text = session ["month"].ToString();
Label2.Text = session ["expense1"].ToString();
Label3.Text = session ["price1"].ToString();

好吧,我的问题是,如何可以在下拉菜单中一个月只能选择一次?比方说,如果用户选择Febuary,下一次如果他登录,他不能选择febuary了。我已经使用这个code:

Ok, my question is, how can make the month in drop down menu can be selected only once? Lets say, if the user choose Febuary, next time if he login, he cant choose the febuary anymore. I have used this code:

asp:DropDownList ID="DropDownList2" runat="server" 
        onchange="if(this.value!='Please choose') this.disabled='true';" Font-Bold="True">
        <asp:ListItem>Please choose</asp:ListItem>
        <asp:ListItem>January</asp:ListItem>
        <asp:ListItem>Febuary</asp:ListItem>
        <asp:ListItem>March</asp:ListItem>

但问题是,当我选择了3月,下一个页面就应该显示三月是不是?但是,它显示请选择'。所以,我真的希望有一个人在这里可以帮助我。谢谢你。

But the problem is when i chose March, in the next page it supposed to show March isnt it? But, it shows 'Please choose'. So, i really hope there's someone here can help me out. Thank you.

推荐答案

为什么不尝试以下操作:

Why not try the following:

ASPX

<asp:DropDownList ID="DropDownList1" runat="server" Font-Bold="True" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
    <asp:ListItem Text="Please choose" Value=""></asp:ListItem>
    <asp:ListItem Text="January" Value="January"></asp:ListItem>
    <asp:ListItem Text="February" Value="February"></asp:ListItem>
    <asp:ListItem Text="March" Value="March"></asp:ListItem>
</asp:DropDownList>

C#

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (Session["Month"] != null)
        {
            if (DropDownList1.SelectedValue == Session["Month"])
            {
                DropDownList1.SelectedValue = string.Empty;
            }
            else
            {
                Session["Month"] = DropDownList1.SelectedValue;
            }
        }
    }

请这是你的第一页上的ASPX和C#。

Make this is the ASPX and C# on your first page.

这篇关于禁用/被选中后,在下拉菜单中删除值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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