zoukankan      html  css  js  c++  java
  • extjs使用gridPanel演示基于asp.net使用json传送数据

    1. 先编写一个aspx页面用于从数据库生成json数据之用,暂取名叫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));

          }

      //////////////////////////////////////////////////////////////////////////////////////////////////

      接着,编写另一个aspx,在基中插入如下js代码:

      <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: 'ProductID', dataIndex: 'ProductID'
              },
              {
                  header: 'ProductName',
                  dataIndex: 'ProductName'
              },
              {
                  header: 'Chai',
                  dataIndex: 'Chai'
              }
          ]);
          var grid = new Ext.grid.GridPanel({
              title: "Products table",
              height: 550,
              800,
              ds: ds,
              columns: [new Ext.grid.RowNumberer(), {
                  header: 'ProductID', 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: '正在加载数据,请稍侯……'
              }

          });
          grid.render(document.body);
      });
          </script>
      </head>
      <body>
          <div id = "hello"></div>
          <form id="form1" runat="server">
          <div>
          </div>
          </form>
      </body>

  • 相关阅读:
    facebook's HipHop for PHP: Move Fast
    使用Linux(CentOS)搭建SVN服务器全攻略
    PHP内置的预定义常量大全
    用PHP纯手工打造会动的多帧GIF图片验证码
    PHP的unset究竟会不会释放内存?
    请远离include_once和require_once
    真希望能夠統一一下接口
    Linux下同步网络时间
    mongo 报connect@src/mongo/shell/mongo.js:251:13错误的解决方式
    spring Aop实现防止重复提交
  • 原文地址:https://www.cnblogs.com/perock/p/2558314.html
Copyright © 2011-2022 走看看