将数据从 ASP.net 返回到 ExtJS 网格 [英] Returning data from ASP.net to an ExtJS Grid

查看:21
本文介绍了将数据从 ASP.net 返回到 ExtJS 网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个用 html 和 javascript(通过 ExtJS)编写的网格原型/模型,我现在需要在 ASP.net Web 应用程序中实现它.有没有人有任何关于如何将数据传递到网格(特别是 GroupingStore)的指针.

I've been given a prototype/mockup of a grid written in html and javascript (via ExtJS) that I now need to implement within an ASP.net web application. Does anyone have any pointers as to how to pass data to the grid (to a GroupingStore, specifically).

我不希望有大量返回 XML/JSON 的 Web 服务或帮助程序页面,所以如果有一种方法可以使用客户端回调或页面方法(你能不能告诉我我对两者都不是特别熟悉 - 流行语宾果游戏)!) 或类似的,那将是首选.

I'd rather not have a proliferation of web services or helper pages returning XML/JSON so if there's a way to use Client callbacks or Page Methods (Can't you tell I'm not particularly familiar with either - buzzword bingo!) or somesuch, that would be preferred.

请不要推荐我使用 jQuery、内置的 ASP.net 网格或任何其他 UI 框架.ExtJS 网格的使用是由权力授权的,所以这就是我正在使用的网格,无论好坏:)

Please, no recommendations that I use jQuery, the built-in ASP.net grid, or any other UI framework. The use of the ExtJS grid has been mandated by the powers that be, so that's the grid I'm using, for better or worse :)

推荐答案

这是一个低技术解决方案.它不需要使用网络服务或任何其他附加技术.

Here's a low tech solution. It doesn't require use of web services or any other additional technologies.

第一步

有一个 ASPX 页面,它接受一个参数,并像这样调用:

Have an ASPX page that takes one paramter, and invoked like this:

http://mysite.com/query.aspx?sql=select * from orders where status = 'open'

第 2 步

在后面的代码中,做这样的事情

In the code behind, do something like this

void Page_Load(object sender, EventArgs e)
{
   Response.ContentType="text/json"; 
   DataTable contents = ExecuteDataTable(Request["sql"]);
   Response.Write( JRockSerialize( contents ) );
   Response.End();
}

您可以使用 JRock 将数据表序列化为 JSON.恕我直言,这提供了最干净的 JSON.

You can use JRock for serializing a data table to JSON. IMHO this gives the cleanest JSON.

这样就将 DataTable 转为 JSON 排序...

So that's getting DataTable to JSON sorted...

警告:这显然是一个简单的例子.您不应该在查询字符串上传递 SQL,因为它不安全(您可以改用命名查询和参数).

步骤 3

在您的 ExtJS 代码中,使用 Json 数据存储创建一个网格,如下所示 扩展示例.使用适当的查询字符串参数将数据存储 url: 设置为您的 query.aspx 页面的数据存储.

In your ExtJS code, create a grid with Json datastore as shown in this Ext example. Set the data store url: to that of your query.aspx page with appropriate query string parameters.

您还需要为网格设置列,再次在 ExtJs 示例中显示.

You'll also need to set the columns up for the grid, again shown in the ExtJs example.

或者……

当我最近查看 Coolite 样本 时,我印象非常深刻.他们是 ExtJS 的合作伙伴,并提供了良好的 ASP.NET &ExtJS 经验.不,我不为他们工作 :) 我没有尝试过他们的网格,但它可能是无痛的(有代价).

I was really impressed when I looked at the Coolite samples recently. They are an ExtJS partner and provide a good ASP.NET & ExtJS experience. And no, I don't work for them :) I haven't tried their grid, but it might be painless (at a price).

这篇关于将数据从 ASP.net 返回到 ExtJS 网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆