前台页面:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<%-- <link type="text/css" rel="stylesheet" href="/css/jquery.autocomplete.css" />
<script src="/css/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="/css/jquery.autocomplete.js"></script>--%>
<link href="/css/jquery-ui-1.10.4.custom.css" rel="stylesheet"
type="text/css" />
<script src="/css/jquery-1.10.2.js" type="text/javascript"></script>
<script src="/css/jquery-ui-1.10.4.custom.js" type="text/javascript"></script>
<title></title>
<script language="javascript" type="text/javascript">
$(function () {
$("#Button1").hide();
$('#name').autocomplete({
source: strArr,
change: function (event, ui) {
// ui.item is undefined :( where is the problem?
document.getElementById("Button1").click();
}
});
});
</script>
<style type="text/css">
#table
{
margin-left:365px;
margin-top:0px;
width:470px;
}
</style>
</head>
<body style="height: 438px">
<form id="form1" runat="server">
<div>
省份:
<input type="text" runat="server" id="name" /> 城市:
<asp:DropDownList ID="DropDownList2" runat="server" Height="22px" Width="118px"
AutoPostBack="true" onselectedindexchanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
地区:
<asp:DropDownList ID="DropDownList3" runat="server" Height="24px" Width="125px">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" οnclick="Button1_Click" Text="确 定" display="none"/>
<asp:Button ID="Button4" runat="server" Text="重 置" οnclick="Button4_Click" />
</div>
<div id="table">
<asp:GridView ID="GridView1" runat="server" RowStyle-Height="25px"
HeaderStyle-Height="25px" AllowSorting="True"
EmptyDataText="<div align=center><font color=red><br/><br/><B>没有找到相关记录</B><br/><br/></font></div>"
GridLines="None" Width="86%" HorizontalAlign="Center"
AutoGenerateColumns="False"
>
<Columns>
<asp:TemplateField ItemStyle-Width="40px" ItemStyle-Height="25px" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="left">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemStyle HorizontalAlign="Left" Height="25px" Width="40px"></ItemStyle>
</asp:TemplateField>
<%-- <asp:TemplateField ItemStyle-Width="40px" ItemStyle-Height="25px" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="left">
<HeaderTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Text="选" Font-Size="12px" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" Height="20px" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="Chbk" runat="server" />
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="选择" HeaderStyle-Font-Size="12px" ItemStyle-Width="40px" ItemStyle-Height="25px" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="left">
<ItemTemplate>
<asp:CheckBox ID="Chbk" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="tableID" HeaderText="地区ID" ControlStyle-CssClass="Boxx" ControlStyle-Width="150px" SortExpression="tableID">
<ItemStyle HorizontalAlign="Left" Font-Size="12px" Width="80px" />
<ControlStyle CssClass="Boxx" Width="150px"></ControlStyle>
<HeaderStyle HorizontalAlign="Left" Font-Size="12px" />
</asp:BoundField>
<asp:BoundField DataField="cityID" HeaderText="城市ID" ControlStyle-CssClass="Boxx" ControlStyle-Width="150px" SortExpression="cityID">
<ItemStyle HorizontalAlign="Left" Font-Size="12px" Width="80px" />
<ControlStyle CssClass="Boxx" Width="150px"></ControlStyle>
<HeaderStyle HorizontalAlign="Left" Font-Size="12px" />
</asp:BoundField>
<asp:BoundField DataField="tableName" HeaderText="地区名" ControlStyle-CssClass="Boxx" ControlStyle-Width="150px" SortExpression="tableName">
<ItemStyle HorizontalAlign="Left" Font-Size="12px" Width="80px" />
<ControlStyle CssClass="Boxx" Width="150px"></ControlStyle>
<HeaderStyle HorizontalAlign="Left" Font-Size="12px" />
</asp:BoundField>
<asp:BoundField DataField="tableType" HeaderText="地区类型" ControlStyle-CssClass="Boxx" ControlStyle-Width="150px" SortExpression="tableType">
<ItemStyle HorizontalAlign="Left" Font-Size="12px" Width="80px" />
<ControlStyle CssClass="Boxx" Width="150px"></ControlStyle>
<HeaderStyle HorizontalAlign="Left" Font-Size="12px" />
</asp:BoundField>
</Columns>
<FooterStyle BackColor="LightSteelBlue" />
<HeaderStyle BackColor="LightSteelBlue" />
<AlternatingRowStyle BackColor="WhiteSmoke" />
<PagerStyle HorizontalAlign="Left" />
<RowStyle Height="25px"></RowStyle>
</asp:GridView>
<!--底部功能栏-->
<table id="table_id" runat="server" width="99%" border="0" align="center" cellpadding="0" cellspacing="0" style="border-top:1px solid #A3B2CC;">
<tr>
<td height="30" width="28%"> <asp:Button ID="Button2" runat="server" CssClass="Btt" Text="确定所选项" OnClick="Button3_Click" />
</td>
</tr>
</table>
</div>
</form>
<%-- <script language="javascript" type="text/javascript">
$(function () {
$("input").autocomplete({
source: [strArr],
change: function (event, ui) {
// ui.item is undefined :( where is the problem?
alert("2");
}
});
});
</script>--%>
</body>
</html>
strArr是个数组 你可以在前台写一个死的替换掉 也可以在后台动态输入数据库的
后台调用
后台调用
string str = "";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
strArr[i] = ds.Tables[0].Rows[i][0].ToString();
str += "'" + strArr[i] + "',";
}
str = str.Substring(0, str.Length - 1);
ClientScript.RegisterArrayDeclaration("strArr", str);
这样传到前台 最好是写在load事件中。