Today, I have provided an article showing you how to sort the GridView column using a DataView in ASP.NET. When binding the GridView to a Custom object or collection, you need to explicitly handle sorting for the GridView. There are many ways in which a user can sort the GridView column. We can use sorting events for the GridView. Here, you will see a DataView with sort property to sort the column of the GridView. All you have to do is implement and hook it up to your website. First of all you create a table in a SQL Server Database. Create an ASP.NET website and add a GridView to it.
Creating Table in SQL Server Database
Now create a table named UserDetail with the columns Id, Name, Country and City. Set the identity property=true for id. The table looks as in the following:

Now insert data into the table.

Now you have to create a web site.
- Go to Visual Studio 2010
- New-> Select a website application
- Click OK

Now add a new page to the website.
- Go to the Solution Explorer
- Right-click on the Project name
- Select add new item
- Add new web page and give it a name
- Click OK

First of all drag the GridView control from the Data controls on the page. The .aspx Code looks like the following code.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sortgridviewcolumn.aspx.cs"
Inherits="Sortgridviewcolumn" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:gridview id="GridView1" runat="server" cellpadding="4" autogeneratecolumns="False">
<columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Coutry" />
<asp:BoundField DataField="City" HeaderText="City" />
</columns>


Ayush GabaeditedPosted Oct 26, 2012, 6:04 AMEdited Oct 26, 2012, 6:05 AM
I want implement sorting in window application in c#. Please give me reference or code Thanks in Advance