既能输入又能选择的DropDownList控件

早就想做一个这样的控件了,最近在一个项目中遇到了这样的问题,所以就写了一个。

我遇到的需求是既能输入又能选择的DropDownList,其中输入的是课程成绩,选择的是补考、缓考、缺考。

此控件支持取值和赋值。支持IE6、IE7,其他的没测。

 

SelectTextBox.ascx

<style type="text/css">
.cls{
 POSITION:absolute;
}
</style>
<div class="cls" style="WIDTH: 85px;z-index:100" align="center">
<iframe style="position:absolute;z-index:-1;width:expression(this.nextSibling.offsetWidth);height:expression(this.nextSibling.offsetHeight);top:expression(this.nextSibling.offsetTop);left:expression(this.nextSibling.offsetLeft);" frameborder="0" ></iframe>
   <asp:TextBox ID="TextBox1" runat="server" Width="85px" Height="15px" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
</div>
<asp:DropDownList ID="

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要给C# DropDownList控件添加输入搜索功能,可以使用以下步骤: 1. 在页面上添加一个文本框和一个DropDownList控件。 2. 给文本框添加一个onkeyup事件,每当用户输入内容时就会触发该事件。 ```C# <asp:TextBox ID="txtSearch" runat="server" onkeyup="searchDropDownList()"></asp:TextBox> <asp:DropDownList ID="ddlItems" runat="server"></asp:DropDownList> ``` 3. 在JavaScript中编写searchDropDownList函数,该函数将获取文本框中的内容并使用jQuery筛选DropDownList中的项。然后将过滤后的项重新绑定到DropDownList中。 ```JavaScript function searchDropDownList() { var input, filter, ul, li, a, i; input = $("#<%=txtSearch.ClientID %>").val().toUpperCase(); filter = input; var items = $("#<%=ddlItems.ClientID %> option"); for (i = 0; i < items.length; i++) { if (items[i].text.toUpperCase().indexOf(filter) > -1) { items[i].style.display = ""; } else { items[i].style.display = "none"; } } } ``` 4. 在页面加载时,以及DropDownList数据发生变化时,都需要调用searchDropDownList函数来刷新过滤结果。 ```C# protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // 绑定DropDownList数据 BindDropDownList(); // 初始过滤 searchDropDownList(); } } protected void ddlItems_SelectedIndexChanged(object sender, EventArgs e) { // 数据变化时,刷新过滤结果 searchDropDownList(); } ``` 5. 最后,可以在CSS中为DropDownList添加样式以使其更容易被搜索。 ```CSS select { padding: 5px; margin: 0; border: 1px solid #ccc; box-shadow: none; font-size: 14px; line-height: 1.42857143; color: #555; background-color: #fff; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值