Extjs uses gridpanel to demonstrate how to use JSON to transmit data based on Asp.net

Source: Internet
Author: User
  1. First, write An ASPX page for generating JSON data from the database. It is called getdata. aspx.
  2. 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);
    });







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.