Moses' Blog

Living {.net} lifestyle

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

<<  November 2008  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

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 on demand Master/Detail grouping Grid with GridView and ASP.NET AJAX toolkit CollapsiblePanelExtender

Introduction

Earlier this year Matt Berseth posted about Building a Grouping Grid with the ASP.NET 3.5 LinqDataSource and ListView Controls. Then I followed his post with 2 other posts discussing same idea but with different implementation:

Later I got few comments about how to implement that using AJAX, in order to display the details data on demand. At that time Dave was demonstrating the usage of jQuery AJAX on his post Using jQuery to consume ASP.NET JSON Web Services. So I came up with another demo to apply on demand loading of details data in my post GridView Grouping Master/Detail Drill Down using AJAX and jQuery.

Again I got few other comments on how to apply same approach, but using ASP.NET AJAX Control Toolkit CollapsiblePanelExtender control. So here I'm going to provide how to do that using CollapsiblePanelExtender and ASP.NET AJAX PageMethods call to apply on demand loading of details from the master data. You can download the sample and view Demo here.

A look inside CollapsiblePanelExtender Control

The reason why I didn't implement that earlier is that I though that CollapsiblePanelExtender do not expose client events when a panel is about to collapse or expand. But I turn out to be completely wrong. CollapsiblePanelExtender expose 6 useful client events that I can handle:

  1. Expanding
  2. Expanded
  3. ExpandComplete
  4. Collapsing
  5. Collapsed
  6. CollapseComplete

And you can register for these events using client script just as the following:

  1. function pageLoad(sender, args){  
  2.         var cpe = $find("CollapsiblePanelExtenderID");  
  3.         cpe.add_expandComplete(onExpand);  
  4.         cpe.add_collapseComplete(onCollapse);  
  5. }  
  6. function onExpand(s,e){  
  7.         //Code here  
  8. }  
  9. function onCollapse(s,e){  
  10.         //Code here  

 

I assume that you know that pageLoad function will be automatically registered for Application Load event.
I have no idea why these events is not exposed as Control Properties so registering would be much more easier using ASPX markup code like this:

  1. <ajaxcontroltoolkit:CollapsiblePanelExtender ID="cpe" runat="Server"   
  2.       ....  
  3.       OnExpand="onExpand"   
  4.       OnCollapse="onCollapse"/> 

 

Extending the Extender

I like this way and I guess this would give much more cleaner code. So I just extended the CollapsiblePanelExtender control by inheriting for it and added 6 properties that map to the client events:

  1. public class CollapsiblePanelEx : CollapsiblePanelExtender  
  2. {  
  3.   [DefaultValue("")]  
  4.   [ExtenderControlEvent]  
  5.   [ClientPropertyName("expanding")]  
  6.   public string OnExpand  
  7.   {  
  8.      get { return (string)(ViewState["OnExpand"] ?? string.Empty); }  
  9.      set { ViewState["OnExpand"] = value; }  
  10.   }  
  11.   [DefaultValue("")]  
  12.   [ExtenderControlEvent]  
  13.   [ClientPropertyName("expanded")]  
  14.   public string OnExpanded  
  15.   {  
  16.       get { return (string)ViewState["OnExpanded"] ?? string.Empty; }  
  17.       set { ViewState["OnExpanded"] = value; }  
  18.   }  
  19.   [DefaultValue("")]  
  20.   [ExtenderControlEvent]  
  21.   [ClientPropertyName("expandComplete")]  
  22.   public string OnExpandComplete  
  23.   {  
  24.       get { return (string)ViewState["OnExpandComplete"] ?? string.Empty; }  
  25.       set { ViewState["OnExpandComp