Sponsored Links
ASP.NET 2.0 Tutorials
- Advanced Site Functionality - ASP.NET 2.0
- ASP.NET : Dynamic Image control
- ASP.NET 2.0 Creating Web Wizards
- Displaying Master-Detail Data on Separate Pages in ASP.NET 2.0
- ASP.NET Displaying Master-Detail Data on the Same Page
- ASP.NET DataBound Controls - Details View
- ASP.NET : Using a Grid to Display Detail Information
- ASP.NET 2.0 : Adding Sorting and Paging in GridView
- ASP.NET 2.0 Tutorials : GridView Filtering
- ASP.NET GridView Control
- ASP.NET 2.0 Training : Data Bound Controls
- ASP.NET 2.0 Free Tutorials : SqlDataSource Control
- ASP.NET 2.0 Training : Data Source Object Model
- ASP.NET 2.0 Free Training : Setting Application-Level Caching
- ASP.NET 2.0 Tutorials : Configuring Page-Level Caching
- ASP.NET 2.0 Free Tutorials : Managing Membership and Roles
- ASP.NET 2.0 Free Tutorials : State Management And Caching in ASp.net 2.0
- Forms Authentication in ASP.NET 2.0
- ASP.NET 2.0 Training : ASP.NET Security
- ASP.NET 2.0 Training : Customizing the Session State Mechanism
Tutorials
ASP.NET 2.0ASP.NET 2.0 : Adding Sorting and Paging in GridView
Table of Contents
ASP.NET 2.0 : Adding Sorting and Paging in GridView
ASP.NET 2.0 - Event handler for Sorting Event
ASP.NET 2.0 - GridView Control DataASP.NET 2.0 : Adding Sorting and Paging in GridView
ASP.NET 2.0 Free Training
Adding Sorting and Paging in GridView
In this tutorial you will learn adding sorting and paging in a GridView Control, Implement Two Column Sorting, Create Code for Custom Sorting, Editing the GridView control data, Deleting Displayed Records, Inserting Records and Using Templates.
Adding Sorting and Paging
Sorting and paging can be added to the GridView control without writing any code.
1. In Design view, right-click the GridView control, and then click Show Smart Tag.
2. On the GridView Tasks menu, select the Enable Sorting box.
3. The column headings in the GridView control change to links.
4. On the GridView Tasks menu, select the Enable Paging box.
5. A footer is added to the GridView control with page number links.
6. Optionally, use the Properties window to change the value of the PageSize property from 10 to a smaller page size.
7. Press CTRL+F5 to run the page.
8. The GridView control is displayed with StudentID, StudentName, StudentAge and CourseId columns. The column headings can be clicked to sort by the contents of that column.

9. Close the browser.
Implementing Two Column Sorting
At this point, the contents of the table can be sorted on the basis of a single column. However, there may be situations where the developer needs to provide an interface to sort data on the basis of two or more columns. To implement two-column sorting, custom sorting features may be added. In this section, let us add a DropDownList control to specify a second column to sort the grid. The DropDownList control will display the names of columns from the StudentMaster table that users can sort by.
1. In the Default.aspx page, switch to Design view.
2. In the Toolbox, from the Standard group, drag a DropDownList control onto the page.
3. Right-click the DropDownList control, click Show Smart Tag, and then on the Common DropDownList Tasks menu, click Edit Items.

4. In the ListItem Collection Editor dialog box, click Add, and set Text and Value to StudentName.
5. Click Add to add another list item, and then set Text and Value to CourseId.
6. Click Add, and then set Text and Value to StudentAge.
7. Click Add, and then set Text and Value to StudentId.

8. Set Selected to True.
9. Click OK.
10. On the Common DropDownList Tasks menu, select the Enable AutoPostBack box.

11. In the Toolbox, from the Standard group, drag a Label control onto the page.
12. Right-click the Label control, click Properties, and then set ID to LabelSortDisplay.
Creating Code for Custom Sorting
For custom sorting, we now write an event handler for the GridView control's Sorting event. The Sorting event is raised when the user clicks a column heading in the GridView control.
Comments
WhoCares said:
| More interesting would be custom paging with custom sorting. Your sample is trivial. |
yogarajan said:
|
Hi all, I need to display two sets of records. The second one should come under the first set of records and also second one uses the first one's unique id. for example, First table values id Show/hide button checkbox category 1 car (parent) Maruthi (child) BMW(child) HeroHonda(child) Yamaha(child) 2 bike 3 fruits Apple Orange Mango . . . (etc) 1. if i click show button that time only child grid is show . button caption change to 'hide' 2. if i click hide button that time only child grid is hide. button caption change to 'show' 2. if i select parent checkbox (ie. checked)(ex. parent -> car ) that corresponding child grid (ex. child -> Maruthi, BMW, HeroHonda, Yamaha) also select(ie. checkbox checked) ----------- So, How to Do it?. |
Rahul said:
|
Hi yogarajan, You can do it by little practice. Thanks for this precious question. |
geetha said:
|
Hi, I am having checkbox column in my gridview.When I select the checkbox in header,All checkboxes in the row also selected.But when I click the page number to view the next page,the checkboxes become unselected.This is my problem that all checkboxes should be in selection even in pagination.Answer me. |
Sponsored Links
