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

问题描述

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



我宁愿不增加网页服务或帮助页面返回XML / JSON,所以如果有办法使用客户端回调或页面方法(不可以告诉我不是特别熟悉任何一个流行语bingo!)或somesuch,这将是首选。



请不要建议我使用jQuery,内置ASP.net网格或任何其他UI框架。 ExtJS网格的使用已被强制使用,因此我正在使用的网格越来越多:)

解决方案

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



步骤1



有一个ASPX页面需要一个参数,并像下面这样调用:

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

步骤2



在后面的代码中,执行这样的操作

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

您可以使用将数据表序列化为JSON。
嗯,这给了最干净的JSON。



所以这样得到 DataTable 到JSON排序...



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



步骤3



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



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



另外...



当我看着最近。他们是ExtJS合作伙伴,并提供了一个很好的ASP.NET& ExtJS经验。不,我不为他们工作:)我没有尝试过他们的网格,但它可能是无痛的(价格)。


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).

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.

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.

Step 1

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

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

Step 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();
}

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

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

WARNING: This is obviously a simplistic example. You shouldn't pass SQL on the query string as it is not secure (your could use named queries and parameters instead).

Step 3

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.

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

Alternatively...

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网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 07:23