tags:

views:

17

answers:

1

Hello,

I am working on asp.net project and using Gridview control on one of the pages. I want Accordion style with table look like view (with columns) on Gridview. This is what I want to do. Say, I have columns called name, ID, Name, and Year and have a couple of rows like,

  1. Ford 2010
  2. Honda 2010
  3. Suzuki 2010
  4. ...

Now what I want do is that I want to make each row expandable, so that if I click 1 in above example, the row1 will expand further and give more details like, 1 F

  1. Ford 2010
    • There are 30 vehicles found.

Would this be possible in Gridview? Thanks for your help.

A: 

Yes, this is possible within a GridView through the use of ItemTemplates. You would define a basic ItemTemplate with the basic details, and then do a little bit of custom programming with the additional details you want to display instead of using the default databinding through the OnRowDataBound event.

If all you're doing is displaying a label with the count of vehicles found, you can include a label control in your ItemTemplate and display/hide the label depending on if the SelectedIndex matches the row being bound.

If you're looking to do something a little more fancy when the selected row, I'd suggest doing an "override" of the EditItem template. You can use the EditItem template to display a complete different layout of the selected row, and test for this through the EditIndex property of the GridView. The other advantage of this is that you could use the "inline" binding method of getting the data in your GridView (you'll see the <%= or <%# tags in the .aspx page) without a lot of coding in the code behind page.

For some more details on the general databinding process (which includes itemtemplates), check out this tutorial on the ASP.net site.

Also check out the Master/Detail article links along the sidebar of the page. One of those solutions might fit your needs nicely as well.

Dillie-O