Disable/remove value in dropdown menu after being

2019-03-03 07:26发布

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();

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>

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.

1条回答
不美不萌又怎样
2楼-- · 2019-03-03 08:08

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;
            }
        }
    }

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

查看更多
登录 后发表回答