简体   繁体   English

根据 DropDownList 选定值显示带有文本框的隐藏 DIV

[英]Show Hide DIV with TextBox based on DropDownList Selected Value

In this I want to popup hidden div when click the drop-down value.在此我想在单击下拉值时弹出隐藏的 div。 My drop down list values get from database.我的下拉列表值从数据库中获取。 So it fill in dynamical.所以它填充动态。

<tr style="padding-top: 10px" class="table-row">
    <td class="auto-style1" style="padding-left: 20px; padding-top: 10px;">Select Report Type</td>
    <td style="padding-top: 10px" class="auto-style2">
        <asp:DropDownList ID="reportTypeDropDownList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="reportTypeDropDownList_SelectedIndexChanged"></asp:DropDownList><br>
    </td>
</tr>


In above its my drop down list..I blinded data to it from database.

<div style="background-color:aquamarine"  id="div1">
<table>

<tr>
    <td>From Date</td>
    <td>
        <asp:TextBox ID="fromDateTextBox" runat="server"></asp:TextBox>
        <asp:CalendarExtender ID="fromDateTextBox_CalendarExtender" runat="server" TargetControlID="fromDateTextBox">
        </asp:CalendarExtender>
    </td>
</tr>
<tr>
    <td>To Date</td>
    <td>
        <asp:TextBox ID="toDateTextBox" runat="server"></asp:TextBox>
        <asp:CalendarExtender ID="toDateTextBox_CalendarExtender" runat="server" TargetControlID="toDateTextBox">
        </asp:CalendarExtender>
        <asp:Button ID="viewButton" runat="server" OnClick="viewButton_Click" Text="View" />
    </td>
</tr>
</table>
</div>

This is the div what i want to popup when click the value这是我想在单击值时弹出的 div

protected void reportTypeDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
    ReportDataAccess reportDataAccess = new ReportDataAccess();

    if (reportTypeDropDownList.SelectedValue=="1")
    {
        //... some logic
    }
}

in this code I tried to do it in report.aspx.cs .在这段代码中,我试图在report.aspx.cs做到这report.aspx.cs

So help me!所以帮帮我吧!

You should try to use JQuery for this.为此,您应该尝试使用 JQuery。 As an example,举个例子,

    <div id="hiddenDiv"> 
      //Content 
    </div>

   <select id="testSelection">
      //options
   </select>

If this is the div and the select you have, you could use JQuery to capture the change event,如果这是您拥有的 div 和选择,则可以使用 JQuery 来捕获更改事件,

 $('#testSelection').on('change', function() {
 if(this.value == 1)
      $('#hiddenDiv').show();
    })

if you do not have an id for the select field and if there is no any other selection in the code use,如果您没有选择字段的 id 并且代码中没有任何其他选择,请使用

$('select').on('change', function() {
if(this.value == 1)
  $('#hiddenDiv').show();
})

The HTML Markup consists of an ASP.Net DropDownList and a TextBox placed inside a Panel control. HTML 标记由一个 ASP.Net DropDownList 和一个放置在 Panel 控件中的 TextBox 组成。 The DropDownList has been assigned an OnSelectedIndexChanged event handler and the AutoPostBack property is set to True. DropDownList 已分配一个 OnSelectedIndexChanged 事件处理程序,并且 AutoPostBack 属性设置为 True。 The Panel control is hidden by setting Visible property to False.通过将 Visible 属性设置为 False,可以隐藏 Panel 控件。 Do you have Passport?你有护照吗?

 <asp:DropDownList ID="ddlHasPassport" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList_Changed"> <asp:ListItem Text="No" Value="N" /> <asp:ListItem Text="Yes" Value="Y" /> </asp:DropDownList> <hr /> <asp:Panel ID="pnlTextBox" runat="server" Visible="false"> Passport Number: <asp:TextBox ID="txtPassport" runat="server" /> </asp:Panel>

Showing Hiding TextBox based on DropDownList selection in ASP.Net When an item (option) is selected in the DropDownList, the selected value is checked.在 ASP.Net 中显示基于 DropDownList 选择的隐藏 TextBox 当在 DropDownList 中选择一个项目(选项)时,选中的值会被选中。

Follow this link [ https://dotnetsnippest.blogspot.com/2019/07/show-hide-textbox-based-on-dropdownlist.html][1]按照此链接 [ https://dotnetsnippest.blogspot.com/2019/07/show-hide-textbox-based-on-dropdownlist.html][1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM