GridPanel bind background data and pagination demo

Source: Internet
Author: User

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 () %>

<%

}
}

%>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.