【问题标题】:Is it possible to open <asp:DropDownList> using <asp:LinkButton> on ASP.NET?是否可以在 ASP.NET 上使用 <asp:LinkBut​​ton> 打开 <asp:DropDownList>?
【发布时间】:2021-06-09 00:27:38
【问题描述】:

我一直在寻找在我的 asp.net 网站上使用我的&lt;asp:LinkButton&gt; 作为我的&lt;asp:DropDownList&gt; 的下拉控件的方法,但搜索结果总是建议通过&lt;"select"&gt; 或 。我的&lt;asp:DropDownList&gt; 没有问题,只是当我在上面应用&lt;CssClass="form-control"&gt; 时,它没有显示箭头,这表明它确实是一个下拉列表(我猜它没有包含在 css 模板中我下载了):

这是我的代码:

<div class="col-md-6 pl-1">
  <div class="form-group">
    <asp:Label ID="Label4" runat="server" Text="Branch"></asp:Label>
    <asp:DropDownList ID="ddlBranch" runat="server" CssClass="form-control">
        <asp:ListItem>Calamba</asp:ListItem>
        <asp:ListItem>Tanauan</asp:ListItem>
        <asp:ListItem>San Pablo</asp:ListItem>
    </asp:DropDownList>
  </div>
</div>

因此,我在另一个 &lt;asp:DropDrownList&gt; 上所做的是将它放在 &lt;div class="input-group"&gt; 中,并在其旁边附加一个 &lt;asp:LinkButton&gt;:

这是我的代码:

<div class="col-md-5 pr-1">
  <asp:Label ID="Label3" runat="server" Text="Account Type"></asp:Label>
    <div class="input-group">
        <asp:DropDownList ID="ddlAccountType" runat="server" CssClass="form-control" Height="2.7em" OnSelectedIndexChanged="ddlAccountType_SelectedIndexChanged">
            <asp:ListItem>Savings</asp:ListItem>
            <asp:ListItem>Current</asp:ListItem>
            <asp:ListItem>Checking</asp:ListItem>
        </asp:DropDownList>
        <div class="input-group-append">
            <div class="input-group-text">
                <asp:LinkButton ID="btnAccountType" runat="server" Font-Underline="False" ForeColor="Black" CssClass="nc-icon nc-minimal-down" />
            </div>
        </div>
       </div>
    </div>  

当然,当我点击链接按钮时,它只是重新加载页面,并没有打开下拉列表。我的问题是是否真的有办法将我的&lt;asp:LinkButton&gt; 连接到&lt;asp:DropDownList&gt; 或没有?非常感谢您回答我的问题!

【问题讨论】:

  • 你需要 Javascript。
  • @John ,是的,已经掌握了要点,但我似乎找不到正确的代码。不过仍在尝试。
  • @John 谢谢你的链接,我会确保检查它作为我未来的参考。

标签: javascript c# jquery asp.net webforms


【解决方案1】:

更新!!!

我不知道这是否可以被视为一种解决方案,但它给了我想要的结果,所以......我所做的是我使用 自从我下载的 CSS 模板没有相应的样式,并根据我从模板中获得的 为它制作自己的样式。

在&lt;style&gt; 之前在&lt;/head&gt; 上编码 (注意:我只是从我拥有的模板的 .form-control 类中复制了它的 css):

<style>
      .accordion {
          background-color: #FFFFFF;
          border: 1px solid #DDDDDD;
          border-radius: 4px;
          color: #66615b;
          line-height: normal;
          height: auto;
          font-size: 14px;
          transition: color 0.3s ease-in-out, border-color 0.3s ease-in-out, background-color 0.3s ease-in-out;
          box-shadow: none;
      }
          .accordion:focus {
              border: 1px solid #9A9A9A;
              box-shadow: none;
              outline: 0 !important;
              color: #66615B;
          }
  </style>

然后我的&lt;asp:DropDownList&gt; 代码如下:

<div class="col-md-5 pr-1">
     <asp:Label ID="Label3" runat="server" Text="Account Type"></asp:Label>
           <div class="form-group">
                 <asp:DropDownList ID="ddlAccountType" runat="server" CssClass="accordion" Height="2.68em" Width="100%">
                      <asp:ListItem>Savings</asp:ListItem>
                      <asp:ListItem>Current</asp:ListItem>
                      <asp:ListItem>Checking</asp:ListItem>
                 </asp:DropDownList>
           </div>
     </div>  

如果我下载的模板上的“.form-control”类也有下拉列表的样式,这无论如何都不是问题。

顺便说一句,对编辑我的问题以使其更形象的人表示敬意。我实际上是这个平台的新手,所以我仍然不习惯它的某些功能。非常感谢!

也感谢@John 的链接!我会去检查一下,以防我将来需要它作为参考。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-15
    • 1970-01-01
    • 2018-12-24
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多