Front-end page:
<Head>
<Title> bind background data </title>
<Script type = "text/javascript" src = "ext-3.1.1/adapter/ext/ext-base.js"> </script>
<Script type = "text/javascript" src = "ext-3.1.1/ext-all.js"> </script>
<Link href = "ext-3.1.1/resources/css/ext-all.css" rel = "Stylesheet"/>
<Script type = "text/javascript">
Ext. onReady (function (){
// Begin
// Create a column
Var cm = new Ext. grid. ColumnModel (
[
{Header: "User ID", name: "ID", sortable: true },
{Header: "UserName", name: "UserName", sortable: true },
{Header: "Age", name: "Age", sortable: true}
]);
// Create a recode format
Var recode = new Ext. data. Record. create ([
{Name: "ID "},
{Name: "UserName "},
{Name: "Age "}
]);
// Create JSONreader
Var reader = new Ext. data. JsonReader ({
TotalProperty: "count", // This property is the total number of specified Record Sets (optional) the property which contains the total dataset size (optional)
Root: "root"
}, Recode );
// Create a store and return a recode
Var store = new Ext. data. Store ({
Url: "GetUserDataJson. aspx", // access server data
Reader: reader
})
Store. load ({params: {start: 0, limit: 3}); // pass the Parameter
Var gridpanel = new Ext. grid. GridPanel ({
Title: "retrieving data from the background ",
Height: 500,
Store: store,
Cm: cm,
Bbar: new Ext. PagingToolbar ({pageSize: 3, store: store, displayInfo: true, displayMsg: "display no. {0 }~ {1}, a total of {2} records ", emptyMsg:" No data to be displayed "}), // create a page
RenderTo: "gpanel"
});
// End
})
</Script>
</Head>
<Body>
<Div id = "gpanel"> </div>
</Body>
Background page:
<%
Int start = int. Parse (Request. Params ["start"]. ToString ());
Int limit = int. Parse (Request. Params ["limit"]. ToString ());
String sqlcon = ConfigurationManager. ConnectionStrings ["mycon"]. ConnectionString;
Using (System. Data. SqlClient. SqlConnection con = new System. Data. SqlClient. SqlConnection (sqlcon ))
{
String SQL = string. format ("select top {0} * from tuser where id not in (select top {1} id from tuser order by id desc) order by id desc", limit, start );
Using (System. Data. SqlClient. SqlCommand cmd = new System. Data. SqlClient. SqlCommand (SQL, con ))
{
Con. Open ();
System. Data. SqlClient. SqlDataReader reader = cmd. ExecuteReader ();
StringBuilder allStr = new StringBuilder ();
AllStr. Append (@ "{root :[");
Int I = 0;
While (reader. Read ())
{
I ++;
AllStr. append ("{ID: '" + reader ["Id"]. toString () + "', UserName:'" + reader ["UserName"]. toString () + "', Age:'" + reader ["age"]. toString () + "'},");
}
AllStr = allStr. Remove (allStr. Length-1, 1 );
AllStr. Append (@ "], count: '10 '}");
%>
<% = AllStr. ToString () %>
<%
}
}
%>