Let's take a look at how to use jquery to achieve a simple selection of the table.
1:$ ("#<%=gridview1.clientid%> tr") selects all rows of the table;
2:not (": First"): Remove the header row;
3:filter (": Contains (' + FilterText + ')"): From the selected line above, filter the rows that contain filtertext in the travel text display;
4: Add the last sentence KeyUp () to trigger the KeyUp event after the commit. (But it doesn't work here because the client control I'm using has no viewstate
If the server-side control will see his role.
The power of the jquery selector allows us to save simple filters that implement the client. Finally add a sentence about table filter There are jquery plug-ins available
Let's take a look at how to use jquery to achieve a simple selection of the table.
$ (function () {
$ ("#text1"). KeyUp (function () {
var FilterText = $ (this). Val ();
$ ("#<%=gridview1.clientid%> tr"). Not (": a"). Hide (). Filter (": Contains (' + FilterText + ')"). Show ();
}). KeyUp ();
});
Front Code
<%@ page language= "C # autoeventwireup=" true "codefile=" jquerytablefilter.asp tutorial X.cs "inherits=" Jquerytablefilter "%>
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://mb.111cn.net/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<title></title>
<script src= "script/jquery-1.3.2-vsdoc. Web Effects" type= "text/Web Effects" ></script>
<script type= "text/web Effects" >
$ (function () {
$ ("#text1"). KeyUp (function () {
var FilterText = $ (this). Val ();
$ ("#<%=gridview1.clientid%> tr"). Not (": a"). Hide (). Filter (": Contains (' + FilterText + ')"). Show ();
}). KeyUp ();
});
</script>
<body>
<form id= "Form1" runat= "Server" >
<div style= "width:60%;" >
<input id= "Text1" type= "text"/>
<asp:gridview id= "GridView1" runat= "Server" autogeneratecolumns= "false"
datakeynames= "OrderID" datasourceid= "SqlDataSource1"
Horizontalalign= "left" pagesize= ">"
<columns>
<asp:boundfield datafield= "OrderID" headertext= "OrderID" readonly= "true"
sortexpression= "OrderID" insertvisible= "false"/>
<asp:boundfield datafield= "CustomerID" headertext= "CustomerID"
sortexpression= "CustomerID"/>
<asp:boundfield datafield= "EmployeeID" headertext= "EmployeeID"
sortexpression= "EmployeeID"/>
<asp:boundfield datafield= "OrderDate" headertext= "OrderDate"
sortexpression= "OrderDate"/>
<asp:boundfield datafield= "RequiredDate" headertext= "RequiredDate"
sortexpression= "RequiredDate"/>
<asp:boundfield datafield= "ShippedDate" headertext= "ShippedDate"
sortexpression= "ShippedDate"/>
<asp:boundfield datafield= "ShipVia" headertext= "ShipVia"
sortexpression= "ShipVia"/>
<asp:boundfield datafield= "Freight" headertext= "Freight"
sortexpression= "Freight"/>
</columns>
</asp:gridview>
<asp:sqldatasource id= "SqlDataSource1" runat= "Server"
connectionstring= "<%$ connectionstrings:northwindconnectionstring%>"
selectcommand= "SELECT Top * from [orders]" ></asp:sqldatasource>
</div>
</form>
</body>