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:
In this article we learned how to use JQuery effects to enhance the user experience when implementing master-detail GridView scenarios.