简体   繁体   English

将数据从ASP.net返回到ExtJS网格

[英]Returning data from ASP.net to an ExtJS Grid

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. 我已经获得了用html和javascript(通过ExtJS)编写的网格原型/模型,我现在需要在ASP.net Web应用程序中实现。 Does anyone have any pointers as to how to pass data to the grid (to a GroupingStore, specifically). 有没有人有关于如何将数据传递到网格(特别是GroupingStore)的任何指针。

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. 我宁愿没有大量的Web服务或辅助页面返回XML / JSON,所以如果有办法使用客户端回调或页面方法(你不能告诉我我也不是特别熟悉 - 流行语宾果游戏!)或者某些人,这将是首选。

Please, no recommendations that I use jQuery, the built-in ASP.net grid, or any other UI framework. 请不要使用jQuery,内置ASP.net网格或任何其他UI框架的建议。 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 :) ExtJS网格的使用是由权力强制执行的,所以这就是我正在使用的网格,无论好坏:)

我相信一个简单地为你的页面返回json结构的服务是最好的选择,在应用程序而不是页面方法中很好地抽象和重用。

Here's a low tech solution. 这是一种低技术解决方案。 It doesn't require use of web services or any other additional technologies. 它不需要使用Web服务或任何其他附加技术。

Step 1 步骤1

Have an ASPX page that takes one paramter, and invoked like this: 有一个ASPX页面需要一个参数,并调用如下:

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

Step 2 第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. 您可以使用JRock将数据表序列化为JSON。 IMHO this gives the cleanest JSON. 恕我直言,这给了最干净的JSON。

So that's getting DataTable to JSON sorted... 因此,将DataTable变为JSON排序......

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). 您不应该在查询字符串上传递SQL,因为它不安全(您可以使用命名查询和参数)。

Step 3 第3步

In your ExtJS code, create a grid with Json datastore as shown in this Ext example . 在ExtJS代码中,使用Json数据存储创建一个网格,如此Ext示例所示。 Set the data store url: to that of your query.aspx page with appropriate query string parameters. 使用适当的查询字符串参数将数据存储url:设置为query.aspx页面的url:

You'll also need to set the columns up for the grid, again shown in the ExtJs example. 您还需要为网格设置列,再次显示在ExtJs示例中。

Alternatively... 另外...

I was really impressed when I looked at the Coolite samples recently. 最近我看了Coolite样品时给我留下了深刻的印象。 They are an ExtJS partner and provide a good ASP.NET & ExtJS experience. 他们是ExtJS合作伙伴,提供良好的ASP.NET和ExtJS体验。 And no, I don't work for them :) I haven't tried their grid, but it might be painless (at a price). 不,我不为他们工作:)我没有尝试他们的网格,但它可能是无痛的(付出代价)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM