可输入的 Combox(DropDownList)
aspx页面中需要可以输入的combox,在网上找了一个js的插件,效果图如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcYAAADQCAIAAAAS+FZMAAAZk0lEQVR4nO2dy2/bSJ7H9bfwpFsfDPStb77l1rfceMtFufVlkEMATmOyDQg7s8jDSTrtdrJQgk0TSK8MdHaAZCaLGSBtJ+BBtqYfE3uTlkhJVGyLbnXWcdbWHviqIosPiZRZKn4/UcsUWSxWufr3cbGKIiv9wWAw6A/6/cFg0Hdf9vKg3x+4q+3t+/v7o9HB3t7ewNlqJ/D29nZ0/jn03SXyAM5BqcwPRgd7+/tk1n55/Nycnam3vnPI/mAwME1rZLX/8Y979+59/vnnly5dunLlSqPR+Onnn0eWZZoms2p+1oPBoN+3RqON7zfev38/oRmNRn/4w5Xf//7zqNeVK/8yGo0mYH7889GVy1ce/bPoYhRF9uoP/3b18uWrfxvmVqQS88ODy5cvP/iBWFPp9/v9vm0WFlHrqS0D5mr22rQk7TEIfRx4awf9/sA0zYODA8uyDg8PLcs6ODgwTTPlEQb9/mg02tjYOD4+DvwGx+Px69evd3Z2XrOw14/H47Ns1JLxYevfL1/+4+Ne0eUoiDyqD6XmB0OpvV6v3+v1+v1+v+f869sf7KWek8D+aX90d/B/9vvOkpNN307dd3bxs/Jz6Pf91X03rbszmbW7l5uVl4H9shfdHJ1M3SLPXDVrNPqepdQPHz6Mx+NRNOPx+MOHD2fZqABMB5SaH2yl9npGz7B/9Ayj1zN6htFzMYjlnpesF1yXDJ2PEdwrJhfDK6NBJTRCOzEymbFqdi8VcgQCAqXmB0uphq07wzCMnuGZy9aN/cHZatiriVRuGmeTncpNa/QMapW3PpSl5ztvk5M7kZFtP4Mwo18gNxO/Fn51Zq3awcHo5csXR0dHp6enhTUXAGDRqBiGrhu6YfhvhmEYuvOf/cPbohNrnQVnWTcMXdcNQ9fJtYazXvcydfMmkhnOrvRhvU3E0XSnsPTOREI9UMzZq7a3t/fTTz/1er3379//HwA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dS8wdK5RwoVRwSg82Z348a5pQkSZJVk3EhlaYwHDvNWGr143MXlPW2NUu1AAWUyjlQqjhkCzbbtxrjetOwUGednvrowjq6rRmBUjkHShWHDMEWMyDAvqifVqqmJJzkH5lt9bNlSZI+WWnPWkYwmUygVO6BUsVhxmAL+5DZBfUmtthzU8nfpzp6dknC8GpmoFTO+X9j4q6UWy/jWQAAAABJRU5ErkJggg==" alt="" />
前台代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InputComBox.aspx.cs" Inherits="School.Web.TestDemo.InputComBox" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>可输入的combox</title>
<link type="text/css" href="/Scripts/jquery-1.10.4/jquery-ui.min.css" rel="stylesheet" />
<script type="text/javascript" src="/Scripts/jquery-1.10.4/jquery.min.js"></script>
<script type="text/javascript" src="/Scripts/jquery-1.10.4/jquery-ui.min.js"></script>
<style type="text/css">
.appcusser li a {
width: 32px;
background: url(/Images/pro_down.gif);
float: left;
display: block;
height: 33px;
line-height: 30px;
text-align: center;
color: #2b7fbf;
font-weight: bold;
margin-right: 5px;
} .appcusser li span {
display: block;
float: left;
width: 100px;
text-align: right;
padding-right: 5px;
color: #666;
}
.appcusser li label {
display: block;
float: left;
line-height: 28px;
margin-right: 5px;
} ul, li {
list-style: none;
} .custom-combobox {
position: relative;
display: inline-block;
} .custom-combobox-toggle {
position: absolute;
top: 5px;
bottom: 0;
left: 160px;
top: 0;
padding: 0;
height: 32px;
/* 支持: IE7 */
*height: 1.7em;
*top: 0.1em;
} .custom-combobox-input {
margin: 0;
padding: 0.3em;
background-color: #fff;
background-image: none;
color: #333;
height: 22px;
width: 150px;
} .hideA {
background: #f3f3f3;
} .clear {
clear: both;
height: 0;
overflow: hidden;
}
</style>
<script type="text/javascript">
(function ($) {
$.widget("custom.combobox", {
_create: function () {
this.wrapper = $("<span>")
.addClass("custom-combobox")
.insertAfter(this.element); this.element.hide();
this._createAutocomplete();
this._createShowAllButton();
}, _createAutocomplete: function () {
var selected = this.element.children(":selected"),
value = selected.val() ? selected.text() : ""; this.input = $("<input>")
.appendTo(this.wrapper)
.val(value)
.attr("id", "btnShowPro")
.addClass("custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left")
.addClass(" validate[required,maxSize[200]]")
.autocomplete({
delay: 0,
minLength: 0,
source: $.proxy(this, "_source")
})
.tooltip({
tooltipClass: "ui-state-highlight"
}); this._on(this.input, {
autocompleteselect: function (event, ui) {
ui.item.option.selected = true;
this._trigger("select", event, {
item: ui.item.option
});
}, autocompletechange: "_removeIfInvalid"
});
}, _createShowAllButton: function () {
var input = this.input,
wasOpen = false; $("<a>")
.attr("tabIndex", -1)
//.attr("title", "aShow")
.attr("id", "aShow")
//.tooltip()
.appendTo(this.wrapper)
.button({
//icons: {
// primary: "ui-icon-triangle-1-s"
//},
text: false
})
.removeClass("ui-corner-all")
.addClass("custom-combobox-toggle ui-corner-right")
.mousedown(function () {
wasOpen = input.autocomplete("widget").is(":visible");
})
.click(function () {
input.focus(); // 如果已经可见则关闭
if (wasOpen) {
return;
} // 传递空字符串作为搜索的值,显示所有的结果
input.autocomplete("search", "");
});
}, _source: function (request, response) {
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
response(this.element.children("option").map(function () {
var text = $(this).text();
if (this.value && (!request.term || matcher.test(text)))
return {
label: text,
value: text,
option: this
};
}));
}, _removeIfInvalid: function (event, ui) { // 选择一项,不执行其他动作
if (ui.item) {
return;
} // 搜索一个匹配(不区分大小写)
var value = this.input.val(),
valueLowerCase = value.toLowerCase(),
valid = false;
this.element.children("option").each(function () {
if ($(this).text().toLowerCase() === valueLowerCase) {
this.selected = valid = true;
return false;
}
}); // 找到一个匹配,不执行其他动作
if (valid) {
return;
} // 移除无效的值
//this.input
// .val("")
// .attr("title", value + " didn't match any item")
// .tooltip("open");
this.element.val("");
this._delay(function () {
this.input.tooltip("close").attr("title", "");
}, 2500);
//this.input.data("ui-autocomplete").term = "";
}, _destroy: function () {
this.wrapper.remove();
this.element.show();
}
});
})(jQuery); $(function () {
$("#<%=ddlName.ClientID%>").combobox();
$("#toggle").click(function () {
$("#<%=ddlName.ClientID%>").toggle();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<ul class="appcusser">
<li>
<span><asp:TextBox ID="txtID" runat="server" Width="80"></asp:TextBox></span>
<label><asp:DropDownList ID="ddlName" runat="server" CssClass="app_txt2 fl"></asp:DropDownList></label>
<div class="clear"></div>
</li>
<li>
<asp:Button ID="btnSeach" Text="查询" runat="server" />
</li>
</ul>
</div>
</form>
</body>
</html>
后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace School.Web.TestDemo
{
public partial class InputComBox : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string tID = txtID.Text.Trim();
//if (!IsPostBack)
//{
if (string.IsNullOrEmpty(tID))
{
BindDrop();
ddlName.Items.Insert(0, new ListItem(" ", ""));
}
else
{
BindDrop();
int id = 0;
int.TryParse(tID, out id);
Bind(id);
}
//}
} public void Bind(int id)
{
Student student = InitData().SingleOrDefault(s => s.ID == id);
if (student != null)
{
if (ddlName.Items.Contains(new ListItem(student.userName))) //判断ddlName下拉列表中是否存在该值,存在则赋值,不存在则插入ddlName下拉列表中
{
ddlName.SelectedValue = student.userName;
}
else
{
ddlName.Items.Insert(0, new ListItem(txtID.Text.Trim()));
}
}
else
{
ddlName.Items.Insert(0, new ListItem(txtID.Text.Trim()));
}
} public void BindDrop()
{
ddlName.DataSource = InitData();
ddlName.DataTextField = "userName"; //ddlName中DataTextField和DataValueField设置为同一个值,在查询是否存在该值是才可以;或者new ListItem("text", "value")设置text、value值不一样
ddlName.DataValueField = "userName";
ddlName.DataBind();
} public List<Student> InitData()
{
List<Student> listStudent = new List<Student>();
for (int i = 1; i < 11; i++)
{
Student student = new Student(); student.ID = i;
student.userName = "学生" + i;
student.passWord = "123456";
student.Age = i + 20;
student.Address = "北京市顺义区天竺镇" + i + "区";
listStudent.Add(student);
}
return listStudent;
}
} public class Student
{
public int ID { get; set; }
public string userName { get; set; } public string passWord { get; set; } public int Age { get; set; } public string Address { get; set; }
}
}
可输入的 Combox(DropDownList)的更多相关文章
- Combox和DropDownList控件的区别
共同点:都是下拉框控件 不同点:Combox用在winform上,DropDownList用在网页上,且两者绑定方式略有不同 绑定数据例子如下—— 1.Combox绑定 DataTable dtBus ...
- c# winform textbox与combox让用户不能输入
textbox的ReadOnly属性设置为true combox的Enable属性设置为false 运行后效果如下 点击第一个和第二个,会把按钮text赋值给文本框和combox 并且用户不能输入
- .net 既可以输入又可以选择的dropdownlist
第一.<script src="../../../Common/Scripts/combox.js" type="text/javascript"> ...
- MFC的combox禁止键盘输入
项目中有个combox的下拉窗控件,鼠标双击总能存在焦点,并且会修改combox显示的文字,网上查了好多资料,都说修改style,可是我的vs2015里没发现有style的属性,后面修改 modal ...
- DropDownList实现可输入可选择
1.js版本 <div style="z-index: 0; visibility: visible; clip: rect(0px 105px 80px 85px); positio ...
- 在dropDownList中实现既能输入一个新值又能实现下拉选的代码
aspx: <div id="selDiv" style=" z-index:100; visibility:visible; clip:rect(0px 110p ...
- 基于bootstrap的下拉选择 ( combox ) 输入 ( input ) 功能
需求: 在编辑数据的时候,既可以让用户输入,也可以从下拉框中选择 思路: 参照下面的效果图,因为是表格里面的数据,所以下拉框触发按钮和输入框分别为1列,输入列可以设置是否输入(方法:<td co ...
- "不能在 DropDownList 中选择多个项。"其解决办法及补充
探讨C#.NET下DropDownList的一个有趣的bug及其解决办法 摘要: 本文就C#.Net 环境下Web开发中经常使用的DropDownList控件的SelectedIndex属性进行了详细 ...
- MVC控制器获取@Html.DropDownList值
MVC控制器获取@Html.DropDownList值 发表于 2014 年 4 月 1 日 作者 efour — 暂无评论 先贴一段代码,演示@Html.DropDownList的使用. 前台 前台 ...
随机推荐
- p2197 nim游戏
传送门 分析 我们知道最后取完的情况就是所有的a[i]异或和为0 所以只要开始的异或和不为0则先手一定可以将它转化为0 否则不行 所以如果异或和非0则先手胜 代码 #include<bits/s ...
- Luogu 3193 [HNOI2008]GT考试
BZOJ1009 妙! 推荐这篇题解: https://www.luogu.org/blog/Edgration/solution-p3193 考虑设计dp,设$f_{i, j}$表示长串匹配到i,短 ...
- SDUT 2107 图的深度遍历
图的深度遍历 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 请定一个无向图,顶点编号从0到 ...
- SQL Server相关知识和经验的碎片化记录
1.在向服务器发送请求时发生传输级错误 在向服务器发送请求时发生传输级错误. (provider: TCP 提供程序, error: 0 - 远程主机强迫关闭了一个现有的连接.) ---> Sy ...
- 存储类型auto,static,extern,register的区别 <转>
变量和函数的属性包括数据类型和数据的存储类别,存储类别指数据在内存中存储方式(静态和动态),包含auto,static,register,extern四种. 内存中.具体点来说内存分为三块:静态区,堆 ...
- 《Head First Servlets & JSP》-1-前言
<Head First Servlets & JSP>(中文版) BB,KS & BB著, 苏钰函,林剑译,中国电力出版社 数据交互 Web浏览器和Web服务器:通过Htt ...
- 多线程学习-基础(四)常用函数说明:sleep-join-yield
一.常用函数的使用 (1)Thread.sleep(long millis):在指定的毫秒内让当前正在执行的线程休眠(暂停执行),休眠时不会释放当前所持有的对象的锁.(2)join():主线程等待子线 ...
- Java50道经典习题-程序26 求星期
题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 判断第二个字母.分析:用情况语句比较好,如果第一个字母一样,则判断用情况语句或if语句判断第二个字母.周一至周日的英文单词 ...
- C#模拟进度条
自己看源码 using System; namespace ConsoleTest { class Program { static void Main(string[] args) { Consol ...
- Powershell Deploy Service Fabric Application To Local Cluster
之前写过一篇用 Powershell 部署 Service Fabric Application 到本地集群的随笔,感觉过程有点复杂,这次将流程简化,只需要将应用程序打包,加上配置文件就可以了. ...