简体   繁体   English

GridView-从Ajax调用中添加与渲染网格匹配的格式化子行

[英]GridView - add formatted child rows from Ajax call that matches the rendered grid

I have an asp.net webforms site with a rather large GridView. 我有一个带有相当大的GridView的asp.net Webforms网站。 The GridView is rendered from a filtered list of data objects. GridView是从过滤后的数据对象列表中呈现的。

Some of the data objects have children of the same type. 一些数据对象具有相同类型的子代。

In my GridView, I'm initially only showing the parent objects. 在我的GridView中,最初只显示父对象。 I want to be able to expand the parent to show the child objects, via an Ajax call, and insert the new rows under the parent. 我希望能够通过Ajax调用扩展父对象以显示子对象,并在父对象下插入新行。

The catch is, they need to follow the same formatting and rendering rules as the parent, and fit in with all the rest of the existing rows. 要注意的是,他们需要遵循与父代相同的格式和呈现规则,并适合所有现有的其余行。 This means that all columns of the new child needs to fit in the columns of the rest of the rendered grid. 这意味着新子级的所有列都需要适合渲染网格其余部分的列。

I would also like to re-use the existing GridView rendering methods if possible, so I don't have to maintain duplicate code that essentially does the same thing. 如果可能的话,我还想重用现有的GridView渲染方法,因此我不必维护本质上可以做同样事情的重复代码。

I can easily use the DynamicPopulateExtender from the AjaxControlToolkit to call a web service to get the child rows, but that wouldn't easily give me the rendered and formatted HTML that would fit into the already rendered GridView table. 我可以轻松地使用AjaxControlToolkit中的DynamicPopulateExtender来调用Web服务以获取子行,但这不会轻易为我提供适合已呈现的GridView表的呈现和格式化的HTML。

Is there a way to get this to work properly, or is there a different way I should approach this? 是否有办法使它正常工作,或者有其他方法应解决?

Make your Ajax calls and insert the data with jQuery perhaps using a templating engine like jsRender to merge the data. 进行Ajax调用,并使用jsRender之类的模板引擎合并数据,并使用jQuery插入数据。 Use the same css classes for the gridview and template to keep the uniform look you want. 对gridview和模板使用相同的CSS类,以保持所需的统一外观。

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

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