实现输入框能填写能下拉选择,填写时动态提示
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { } using (UsersDataContext con = new UsersDataContext()) { string s = "" ; int count = 0; List<Users> ulist = con.Users.ToList(); for (int i = 0; i < ulist.Count; i++) { if (count > 0) s += ; s += ulist[i].Nickname; count++; } HiddenField1.Value = s; //将需要的信息放到隐藏控件中 } } }
后台数据
<%@ Page Language=AutoEventWireup=CodeFile=Inherits=%> <!DOCTYPE html> <html xmlns=> <head runat=> <meta http-equiv=content=/> <title></title> <script src=></script> </head> <body> <form id=runat=> <div> 用户名: <asp:TextBox ID=runat=list=autocomplete=></asp:TextBox> <datalist id=> <option value=></option> <option value=></option> <option value=></option> <option value=></option> </datalist> <asp:Label ID=runat=Text=></asp:Label> <asp:HiddenField ID=runat=/> </div> </form> </body> </html> <script type => ).val();strs = new Array();//定义数组 strs = b.split(); v = ""; for (var i = 0; i < strs.length;i++) { v += + strs[i] + ; } $().html(v); //取值 从 TextBox 中取 $().change(function () { ).val(); $().html(av); }); </script>
页面展示