Moses' Blog

Living {.net} lifestyle

Away Notice

I'll be away for the next 19 days starting from 30th Sept. I have no internet connection during this period.

Muhammad Mosa

Moses' profile picture
Logo
Software Engineer.
MCT, MCSD.NET,
MCTS: .Net 2.0 Web, Windows, Distributed Applications
MCTS: .Net 3.5 WF Application Development
MCTS: WSS 3.0, MOSS 2007 Configuration & App Dev
MCPD: Enterprise Application Developer

Send mail My Live Space Moses on Facebook Twitter Moses on Technorati

Sponsors



Calendar

<<  October 2008  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar

Recent Comments

Comment RSS

Community Credit

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Building a grouping Grid with GridView and JQuery

Nothing really new on this post, just another way to implement mater/detail representation with nested GridViews with assistance of JQuery. Previously I posted about building same feature using ASP.NET AJAX CollapsiblePanel Extender. that was another example of what Matt Berseth presented in his post about building a grouping grid using ASP.NET 3.5 ListView and Linq.

In this post I'll show how same feature can be implemented using JQuery. Very simple and straight forward.

Requirements:
It is required to download latest version of JQueryin order to be able to use this sample [View Demo].

Implementation:
I've created a new ASP.NET AJAX enabled web site using Visual Studio. And I added a script reference to my script manager:

   1: <asp:ScriptManager ID="ScriptManager1" runat="server" >
   2:     <Scripts>
   3:         <asp:ScriptReference Path="~/scripts/jquery-1.2.3.min.js" ScriptMode="Release" />
   4:     </Scripts>
   5: </asp:ScriptManager>

Using same design I made on my previous post, I started to implement the usage of JQuery. I used JQuery to replace the functioanlity provided by CollapsiblePanelExtender.

JQuery has a method called slideToggle, I used this method to expand and collapse the details grid. Below is the JavaScript method used to handle expand and collapse:

   1: <script type="text/javascript">
   2:     //master: id of div element that contains the information about master data
   3:     //details: id of div element wrapping the details grid
   4:     function showhide(master,detail)
   5:     { 
   6:         //First child of master div is the image
   7:         var src = $(master).children()[0].src;
   8:         //Switch image from (+) to (-) or vice versa.
   9:         if(src.endsWith("plus.png"))
  10:             src = src.replace('plus.png','minus.png');
  11:         else
  12:             src = src.replace('minus.png','plus.png');
  13:         
  14:         //Set new image
  15:         $(master).children()[0].src = src;
  16:         
  17:         //Toggle expand/collapse                   
  18:         $(detail).slideToggle("normal");             
  19:     }
  20: </script>

Both master and details parameters mentioned in the code above, is ID of a DIV element with leading '#' -related to JQuery Syntax-. Those DIV elements are used to wrap both master data and details data:

   1: <div class="group" id='<%#String.Format("customer{0}",Container.DataItemIndex) %>' onclick='showhide(<%#String.Format("\"#customer{0}\"",Container.DataItemIndex) %>,<%#String.Format("\"#order{0}\"",Container.DataItemIndex) %>)'>
   2: ......<!--Master Data-->
   3: </div>
   1: <div id='<%#String.Format("order{0}",Container.DataItemIndex) %>' class="order">
   2: ....<!--Details Data-->
   3: </div>

When you click on first DIV, collapse/expand image will switch, and the second DIV wil toggel its state (collapse/expand). Same thing can be applied to Matt's sample using JQuery.

Download the attached sample to review the code.

kick it on DotNetKicks.com

Posted: Mar 08 2008, 22:02 by mosessaur | Comments (9) RSS comment feed |
  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: ASP.NET | Client Side
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Comments

Add comment


(For Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading