views:

4196

answers:

6

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

A: 

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.

Tom Ritter
A: 

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.

RandomNoob
A: 

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

Slavo
+1 for purchasing the control. How much will it cost (in terms of your time/rate) to make one effectively vs. how much to purchase one? And so many good choices in the .NET world ...
John Rudy
@ Slavo - its not really a mess, I've done it since .NET 1.0. Don't knock it till you try it.
RandomNoob
A: 

Here is a good article on how to create the hierarchical grid:

http://www.progtalk.com/ViewArticle.aspx?ArticleID=54

Matt
A: 

Hey Tom Ritter

Your approach sounds good to me can you please share the ajax solution... I want to implement same thing...

thanks in addvance Yash

-1 This should be a comment beneath Tom Ritter's post, instead of an answer.
John K
A: 

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

Pon Saravanan