ASP.NET - Hierarchical grid view

夙愿已清 提交于 2019-12-24 09:58:40

问题


Any ideas on how I can acheive 'Hierarchical' gridview? Basically I want when the user clicks on the '+', i "expand" and insert new rows without a full page post back.

Does this sound like a lot of AJAX stuff? Or should I read on ASP.NET MVC

Please point me in right direction


回答1:


Another way to do this is the old Grid view inside a Grid view Trick. The basic concept is to have the [+] and the parent data as the Item data in a single templated column. Attach the to click event of the button and set your grid to edit/selected mode. when its in edit mode, render a second grid view with the child data. Although its a gridview inside a gridview, visually it will accomplish a "hierarchical" view.




回答2:


Sample source code for Hierarchical GridView with [-] and [+] to collapse and expand as in VB6 Hierarchical Grid




回答3:


You have two options I suppose:

  • You can render out those rows you want to insert, and the [+] shows them and hides them
  • You don't render them out, and they are sent to the browser via AJAX, and then inserted into the table.

I've done it both ways, and the more gridviewy way to do it is the first, in my opinion. You can create a new templatefield for the [+]; define a child relationship name, and then call GetChildRows (or an equivalent) on each row as you render, having those rows render hidden.




回答4:


@bnkdev - GridView inside a GridView sounds like a total mess.

@Jandwenyi - I suppose you're doing this for a certain scenario and you'll need to reuse it at some point, as unprobable as it may seem now. My suggestion - find a third-party Grid control that would do what you want - there are so many out there.



来源:https://stackoverflow.com/questions/295607/asp-net-hierarchical-grid-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!