这个怎么判断呀,特别是这种项很多的时候

解决方案 »

  1.   

    可以在下拉菜单里设置个“其他”的选项,当选择它的时候,就用js把textbox显示出来。
      

  2.   

    +++
    这个挺好的
    不过这里猜LZ的js不是很熟,建议用DropDownList的AutoPostBack属性设为true,然后在DropDownList的选中事件中判断,如果选中“其他”这个项的值,就把textbox的visible的值设为true就可以显示了
      

  3.   

    他有很多这种选项,每次都autopostback,不好吧。
      

  4.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
        <script type="text/javascript">
            $(function() {
                $("select").change(function() {
                    if ($(this).val() == "-1") {
                        if ($("#txt_" + $(this).attr("id")).length > 0) {
                            $("#txt_" + $(this).attr("id")).show();
                        }
                        else {
                            $(this).after("<input type='text' id='txt_" + $(this).attr("id") + "' name ='txt_" + $(this).attr("id") + "'/>");
                        }
                    }
                    else {
                        if ($("#txt_" + $(this).attr("id")).length > 0) {
                            $("#txt_" + $(this).attr("id")).hide();
                        }
                    }
                });            $("#btnSave").click(function() {
                    var flag = true;
                    $(":selected[value='-1']").each(function() {
                        if ($.trim($(this).parent().next().val()) == "") {
                            flag = false;
                            return false;
                        }
                    });
                    return flag;
                });
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            DropDownList1:<asp:DropDownList runat="server" ID="DropDownList1">
                <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试2" Value="2"></asp:ListItem>
                <asp:ListItem Text="测试3" Value="3"></asp:ListItem>
                <asp:ListItem Text="测试4" Value="4"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList2:<asp:DropDownList runat="server" ID="DropDownList2">
                <asp:ListItem Text="测试5" Value="5"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList3:<asp:DropDownList runat="server" ID="DropDownList3">
                <asp:ListItem Text="测试5" Value="5"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList4:<asp:DropDownList runat="server" ID="DropDownList4">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试2" Value="2"></asp:ListItem>
                <asp:ListItem Text="测试3" Value="3"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList5:<asp:DropDownList runat="server" ID="DropDownList5">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试5" Value="5"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList6:<asp:DropDownList runat="server" ID="DropDownList6">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试2" Value="2"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList7:<asp:DropDownList runat="server" ID="DropDownList7">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试5" Value="5"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList8:<asp:DropDownList runat="server" ID="DropDownList8">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试2" Value="2"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList9:<asp:DropDownList runat="server" ID="DropDownList9">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试2" Value="2"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
           DropDownList10:<asp:DropDownList runat="server" ID="DropDownList10">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试5" Value="5"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList11:<asp:DropDownList runat="server" ID="DropDownList11">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试5" Value="5"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList12:<asp:DropDownList runat="server" ID="DropDownList12">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试2" Value="2"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList13:<asp:DropDownList runat="server" ID="DropDownList13">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试2" Value="2"></asp:ListItem>
                <asp:ListItem Text="测试3" Value="3"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList14:<asp:DropDownList runat="server" ID="DropDownList14">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试2" Value="2"></asp:ListItem>
                <asp:ListItem Text="测试3" Value="3"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList15:<asp:DropDownList runat="server" ID="DropDownList15">
                <asp:ListItem Text="测试5" Value="5"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList16:<asp:DropDownList runat="server" ID="DropDownList16">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试5" Value="5"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList17:<asp:DropDownList runat="server" ID="DropDownList17">
                 <asp:ListItem Text="测试1" Value="1"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList18:<asp:DropDownList runat="server" ID="DropDownList18">
                <asp:ListItem Text="测试5" Value="5"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList19:<asp:DropDownList runat="server" ID="DropDownList19">
                <asp:ListItem Text="测试5" Value="5"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            DropDownList20:<asp:DropDownList runat="server" ID="DropDownList20">
                <asp:ListItem Text="测试5" Value="5"></asp:ListItem>
                <asp:ListItem Text="测试6" Value="6"></asp:ListItem>
                <asp:ListItem Text="测试7" Value="7"></asp:ListItem>
                <asp:ListItem Text="其他" Value="-1"></asp:ListItem>
            </asp:DropDownList><br />
            <asp:Button runat="server" ID="btnSave" Text="提交" onclick="btnSave_Click" />
        </div>
        </form>
    </body>
    </html>
      

  5.   


    protected void btnSave_Click(object sender, EventArgs e)
        {
            Response.Write("DropDownList1:"+(DropDownList1.SelectedValue=="-1"?Request.Form["txt_"+DropDownList1.ClientID]:DropDownList1.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList2:" + (DropDownList2.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList2.ClientID] : DropDownList2.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList3:" + (DropDownList3.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList3.ClientID] : DropDownList3.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList4:" + (DropDownList4.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList4.ClientID] : DropDownList4.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList5:" + (DropDownList5.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList5.ClientID] : DropDownList5.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList6:" + (DropDownList6.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList6.ClientID] : DropDownList6.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList7:" + (DropDownList7.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList7.ClientID] : DropDownList7.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList8:" + (DropDownList8.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList8.ClientID] : DropDownList8.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList9:" + (DropDownList9.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList9.ClientID] : DropDownList9.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList10:" + (DropDownList10.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList10.ClientID] : DropDownList10.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList11:" + (DropDownList11.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList11.ClientID] : DropDownList11.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList12:" + (DropDownList12.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList12.ClientID] : DropDownList12.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList13:" + (DropDownList13.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList13.ClientID] : DropDownList13.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList14:" + (DropDownList14.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList14.ClientID] : DropDownList14.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList15:" + (DropDownList15.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList15.ClientID] : DropDownList15.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList16:" + (DropDownList16.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList16.ClientID] : DropDownList16.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList17:" + (DropDownList17.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList17.ClientID] : DropDownList17.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList18:" + (DropDownList18.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList18.ClientID] : DropDownList18.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList19:" + (DropDownList19.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList19.ClientID] : DropDownList19.SelectedValue));
            Response.Write("<br/>");
            Response.Write("DropDownList20:" + (DropDownList20.SelectedValue == "-1" ? Request.Form["txt_" + DropDownList20.ClientID] : DropDownList20.SelectedValue));
        }
      

  6.   


    我怎么样才能当drodownlist里没值时就调用textbox的值呢?
      

  7.   


    JS我知道呢,我是想知道如果要往数据库里传值,怎么样不选下拉菜单的值的话就自动传TEXTBOX的值到数据库呢!
      

  8.   

    你要自己判断,例如一个DropDownListX就对应一个TextboxX,你判断DropDownListX是否选择的是“其他”之类的选项,如果是,则存储TextBoxX中的值,反之存储DropDownListX中的值。
      

  9.   


    统一调用textbox的值,当drodownlist的值发生变化时,用它的值更新textbox里的值
      

  10.   

    把textbox的Visible设为false;dropdownlist选择“无”,就显示textbox;
    在提交数据库时,判断textbox是否为空,不为空就提交。
    大概:if(dropdownlist.SelectedValue="无")
    {
    this.textbox.Visible = true;
    ……
    }
    else
    {
    ……
    }
    if (!string.IsNullOrEmpty(textbox))
    {
    提交……
    }
    else
    {
    ……
    }