1
votes

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

4

4 Answers

1
votes

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.

1
votes

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

0
votes

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.

0
votes

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