---
title: "Sorting in gridview using tablesorter.js in asp.net"  
description: "In this article I  am going to implement sorting in asp.net gridview using tablesorter.jsStep by step1.Open visual studio2.Create a web application3.A"  
author: "Ashok Aryan"  
published: 2016-05-16  
updated: 2018-03-14  
canonical: https://www.mindstick.com/blog/11090/sorting-in-gridview-using-tablesorter-js-in-asp-dot-net  
category: "asp.net"  
tags: ["c#", "jquery", "gridview", "sorting"]  
reading_time: 2 minutes  

---

# Sorting in gridview using tablesorter.js in asp.net

In this article I am going to implement sorting in [asp.net](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) [gridview](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net) using tablesorter.js

##### Step by step

**1.** Open [visual studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available)

**2.** Create a [web application](https://www.mindstick.com/articles/13069/progressive-web-application-pwas-all-you-need-to-know-about)

![Sorting in gridview using tablesorter.js in asp.net](https://www.mindstick.com/blogs/aae6ede9-8399-484e-93f2-fc807a5e3c63/images/f024825a-db18-48cd-a91f-613fde68e197.png)

**3.** Add new page

\

**4.** Drag a gridview on the page

![Sorting in gridview using tablesorter.js in asp.net](https://www.mindstick.com/blogs/aae6ede9-8399-484e-93f2-fc807a5e3c63/images/e28eaf68-0eff-4f89-9968-769fd843f096.png)

**5.** On the head section of page call below script and link

\

```
<script src="JS/jquery-1.11.1.js" type="text/javascript"></script>    <link href="dist/css/theme.default.min.css" rel="stylesheet">    <script src="dist/js/jquery.tablesorter.min.js"></script>    <script>        $(document).ready(function () {             $("table").tablesorter();         });         </script>
```

## \

**6.** Grid page source like

## \

```
<asp:GridView ID="GridView1" runat="server" CssClass="tablesorter" CellPadding="4"            ForeColor="#333333" GridLines="None" OnRowDataBound="GridView1_RowDataBound"  >                    </asp:GridView>
```

**7.** In .cs ([code behind](https://www.mindstick.com/forum/2199/call-javascript-s-function-from-code-behind)) I have create a [datatable](https://www.mindstick.com/blog/195/datatable-in-ado-dot-net) with some static record and bind to gridview on [page load](https://www.mindstick.com/articles/12909/how-to-open-first-time-popup-on-page-load-in-website)

| ``` protected void Page_Load(object sender, EventArgs e) { BindGrid(); } private void BindGrid() { DataTable table = new DataTable(); table.Columns.Add("Dosage", typeof(int)); table.Columns.Add("Drug", typeof(string)); table.Columns.Add("Patient", typeof(string)); table.Columns.Add("Date", typeof(DateTime)); // Here we add five DataRows. table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now); table.Rows.Add(21, "Combivent", "Janet", DateTime.Now); table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now); GridView1.DataSource= table; GridView1.DataBind(); } ``` |
| --- |

**\**

**8.** On gridview [rowdatabound](https://www.mindstick.com/forum/12667/gridview-rowdatabound-for-loop-not-working) event

```
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    {        if (this.GridView1.Rows.Count > 0)        {            GridView1.UseAccessibleHeader = true;            GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;          //  GridView1.FooterRow.TableSection = TableRowSection.TableFooter;        }    }
```

**9.** Final result

![Sorting in gridview using tablesorter.js in asp.net](https://www.mindstick.com/blogs/aae6ede9-8399-484e-93f2-fc807a5e3c63/images/e260a065-a47f-42af-b1a2-9756ca2364ba.png)\

## Note : for js and plugin go to below link

## *http://tablesorter.com/docs/*\

---

Original Source: https://www.mindstick.com/blog/11090/sorting-in-gridview-using-tablesorter-js-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
