2由radiobutton选择的相同位置的不同DropDownList

时间:2017-01-28 11:28:31

标签: c# asp.net webforms

是否可以在同一位置设置2个下拉列表。一个下拉列表将显示何时选择单选按钮。

1 个答案:

答案 0 :(得分:0)

您可以使用JQueryCSShtml elements进行2种方法:

HTML:

<input type="radio" id="radio" class="Here you position it">
<select id="ddlFirst" class="Same Position class" style="visibility: hidden;">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
</select>
<select id="ddlSecond" class="Same Position class" style="visibility: hidden;">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
</select>
<input type="button" id="btn">

这是你的JQuery:

<script>
$("#btn").click(function() {
   var radio = $("#radio").val();
   var ddlFirst;
   var ddlSecond;
   if(!radio)
       {
         $("#radio").css("visibility", "Hidden");
         $("#ddlFirst").css("visibility", "Visible");

         $("#ddlFirst").on("click", function() {
            var ddlFirst = $('#ddlFirst').find(":selected").text();
            if(!ddlFirst)
              {
                //same rotation
              }
         });
       }
});
</script>

然后您可以使用ajax

发送值

第二种方法是使用asp.net tags并在您的代码隐藏中管理它们,您应该自己修复CSS

page_load

//visiblity
rdbtn1.Visible = true;
DropDownList1.Visible = false;
DropDownList1.Visible = false;

if(rdbtn1.Checked == true)
   { 
     DropDownList1.Visible = true;
     rdbtn1.Visible = false;
   } 
else if(DropDownList1.SelectedValue != 0)
   { 
     DropDownList1.Visible = false;
     DropDownList2.Visible = true; 
   }
else if(DropDownList2.SelectedValue != 0)
   { 
     //Totally get all your ur controls hidden in this state
     DropDownList2.Visible = false;
   }