In the year 2005 we published an article about creating master-detail GridView control. JQuery was not a first class citizen during that time and most of the work was performed by either plain old vanilla JavaScript or the server side code. With the advent of JQuery we can now create cool master-detail effects easily in less time and less code. This article explains how to spice up master-detail using JQuery.

Data Source:

For the sake of simplicity we have used collections as the data source instead of the database. The scenario revolves around Category and Product classes. The implementation below is used to populate the categories collection and return it to the user interface.



The above code populates the categories collection with some dummy data and assigns ten products to each category. The DataAccess.GetCategories is triggered from the page code behind as shown in the code below:



The gvCategories is the name of the GridView control which is being populated using the categories collection returned from the DataAccess.GetCategories method.

Applying JQuery Effect on the GridView Control:

Before applying JQuery effect let's take a look at the ASPX code for the GridView control.



When the page is loaded for the first time only category name is being displayed as shown in the screenshot below:



The JQuery implementation is shown in the code below:



Basically we are attaching the click function to all the elements on the page whose class name is ".categoryStyle". Inside the click event we use the JQuery siblings function to find the element with the class ".productStyle" and make it show and hide. The effect is shown below:



Conclusion:

In this article we learned how to use JQuery effects to enhance the user experience when implementing master-detail GridView scenarios.

[Download Sample]