![]()
我在TextBox1_TextChanged中重新绑定了一次..效果已经是OK的.现在就是在TEXTBOX1中输入条件市区焦点的时候,页面的刷新有点晃眼,该怎么样处理呢,用AJAX如何处理呢?
另外,TextBox文本框控件,是否有Keydown事件.也就是说在边输入边过滤,并不要等失去焦点的时候再过滤.
请高手解答解答..
俺是新手..
所以请教大家了.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class uuuuu : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConGet();
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
if (TextBox1.Text.Trim() == "")
{
SqlConGet();
}
else
{
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
SqlDataAdapter sqldata = new SqlDataAdapter("Select * from asyuser", sqlcon);
DataSet sqldaset = new DataSet();
DataView sqldaview = new DataView();
try
{
sqlcon.Open();
sqldata.Fill(sqldaset, "asyuser");
sqldaview.Table = sqldaset.Tables["asyuser"];
sqldaview.RowFilter = "userno like " + "'" + TextBox1.Text.Trim() + "'";
GridView1.DataSource = sqldaview;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
Response.End();
}
finally
{
sqlcon.Close();
}
}
}
protected void SqlConGet()
{
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
SqlDataAdapter sqldata = new SqlDataAdapter("Select * from asyuser", sqlcon);
DataSet sqldaset = new DataSet();
DataView sqldaview = new DataView();
try
{
sqlcon.Open();
sqldata.Fill(sqldaset, "asyuser");
sqldaview.Table = sqldaset.Tables["asyuser"];
//sqldaview.RowFilter = "userno like " + "'" + TextBox1.Text.Trim() + "'";
GridView1.DataSource = sqldaview;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
Response.End();
}
finally
{
sqlcon.Close();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="uuuuu.aspx.cs" Inherits="uuuuu" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<style type="text/css">
#TextBox1
{
margin:0 0 1px;padding:0px 0 0 20px!important;padding:0 0 0 20px;background:url(images/Search.gif) no-repeat 0 -1px #fffce9;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Text="查询:"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="用户名:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" AutoPostBack="True"></asp:TextBox>
<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="White"
BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" EmptyDataText="无返回数据:1.请确认查询条件;2.请与管理员联系."
EnableSortingAndPagingCallbacks="True" GridLines="None" AllowPaging="True" AllowSorting="True">
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
</asp:GridView>
</div>
</form>
</body>
</html>