- First, write An ASPX page for generating JSON data from the database. It is called getdata. aspx.
Protected void btntojsonstring_click (Object sender, eventargs E)
{
Sqlconnection con = new sqlconnection ();
Con. connectionstring = "Data Source =.; initial catalog = northwind; Integrated Security = true ";
VaR cmd = new sqlcommand ();
Cmd. Connection = con;
Cmd. commandtext = "select * from products ";
VaR da = new sqldataadapter ();
Da. selectcommand = cmd;
VaR DS = new dataset ();
Da. Fill (DS, "Products ");
VaR dt = new datatable ();
Dt = Ds. Tables ["Products"];
Response. Write (jsonconvert. serializeobject (DT ));
}
//////////////////////////////////////// //////////////////////////////////////// //////////////////
Next, write another aspx and insert the following JSCode:
<LINK rel = "stylesheet" type = "text/CSS" href = "JS/resources/CSS/ext-all.css"/>
<SCRIPT type = "text/JavaScript" src = "JS/ext-base.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "JS/ext-all.js"> </SCRIPT>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<SCRIPT>
Ext. onready (function (){
VaR proxy1 = new Ext. Data. httpproxy ({URL: "getdata. aspx "});
VaR DS = new Ext. Data. Store ({
URL: "getdata. aspx ",
Reader: New Ext. Data. jsonreader ({},
[{
Name: "productid ",
Mapping: "productid"
},
{
Name: "productname ",
Mapping: "productname"
},
{
Name: "chai ",
Mapping: "chai"
},
{
Name: "supplierid ",
Mapping: "supplierid"
},
{
Name: "categoryid ",
Mapping: "categoryid"
},
{
Name: "quantityperunit ",
Mapping: "quantityperunit"
},])
});
DS. Load ();
VaR CM = new Ext. Grid. columnmodel ([{
Header: 'produd d', dataindex: 'productid'
},
{
Header: 'productname ',
Dataindex: 'productname'
},
{
Header: 'chai ',
Dataindex: 'chai'
}
]);
VaR grid = new Ext. Grid. gridpanel ({
Title: "Products table ",
Height: 550,
Width: 800,
DS: ds,
Columns: [New Ext. Grid. rownumberer (),{
Header: 'produd d', dataindex: 'productid'
},
{
Header: 'productname ', dataindex: 'productname'
},
{
Header: 'chai', dataindex: 'chai'
},
{
Header: 'supplierid', dataindex: 'supplierid'
},
{
Header: 'categoryid', dataindex: 'categoryid'
},
{
Header: 'quantityperunit ', dataindex: 'quantityperunit'
}],
Autoscroll: True,
Loadmask :{
MSG: 'loading data. Please wait ...... '
}
});
grid. render (document. body);
});