如何启用下拉列表中的一个值 [英] How to Enable One of the value in Drop Down List

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

问题描述

我的下拉列表包含以下值(其中前两个值显示付款状态)。它位于我项目的管理员端。

1)未支付

2 )已支付

3)已交付



前两个值取决于付款状态。

在这里,如果付款状态为'付费',则启用='假'为'未付',如果状态为'已付款',付款状态为'未付'和'付费' 。

那么如何为这两个值(Unpaid&Paid)启用选择false,以便Admin无法将状态更改为Unpaid或Paid。他只能看到它。但是他可以把它改成Delivered

请帮忙。

I have drop down list with following values(in which first two values shows payment status).Its on Admin side of my project.
1)Unpaid
2)Paid
3)Delivered

First two values are depended upon Payment Status.
Here,I want to Enable='false' to 'Unpaid' if the payment status is 'Paid' & Enable='false' for both 'Unpaid and 'Paid' if Status is 'Delivered'.
So how to enable selection false to these two values(Unpaid & Paid) so that Admin cannot change status to Unpaid or Paid by himself.He can only see it. But he can change it to "Delivered"
Please help.

推荐答案

你可以在下拉列表检查中添加javascript onchange()事件来显示选择不正确的值的警报消息,并显示在下拉框中选择的当前值。

例如如果管理员将值从付费更改为未付或未付到付费,则简单显示警告消息,如选择适当的值并显示其中选择的当前值。
You can add javascript onchange() event on dropdown check to display alert message for improper selected value and display the current value selected in dropdownbox.
e.g. if admin change value from "Paid" to "Unpaid" or "Unpaid" to "Paid" simple shows alert message like "select proper value" and show current value selected in it.


尝试这:

Try this:
<form id="form1" runat="server">
<div>
    <asp:DropDownList ID="ddl1" runat="server" onChange="onChange();" AutoPostBack="False">
        <asp:ListItem></asp:ListItem>
        <asp:ListItem>Unpaid</asp:ListItem>
        <asp:ListItem>Paid</asp:ListItem>
        <asp:ListItem>Delivered</asp:ListItem>
    </asp:DropDownList>
</div>
</form>
<script>
    var ddl = document.getElementById("<%= ddl1.ClientID %>");
    function onChange() {
        var selectedIndex = ddl.selectedIndex;
        var selectedOption = ddl.options[selectedIndex];
        for (var i = 0; i < ddl.length; i++) {

            if (ddl.options[i].value == "Unpaid" && selectedOption.value == "Paid") {

                ddl.options[i].disabled = true;

                break;

            } else if (selectedOption.value == "Delivered") {



                if (ddl.options[i].value == "Unpaid" || ddl.options[i].value == "Paid") {

                    ddl.options[i].disabled = true;



                }

            }

        }

    }



    function disableOption(i) {

        ddl.options[i].disabled = true;

    }

</script>


这篇关于如何启用下拉列表中的一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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