-->

Tuesday, October 13, 2015

Use GridView.Sorting Event in ASP.NET C#

Use GridView.Sorting Event in ASP.NET C#

Introduction

In this article we will learn how to sort gridview data using Gridview columns.I mean to say when we click on gridview columns then data will be in ordered like ascending or descending. If you want to sort available data by using code then you should see this article.

About Sorting 

Sorting means rearranging data either ascending or descending data. you want to perform sorting of the data then you should apply technique to sort of the data . Various techniques are available in logic programming such as Bubble sort, insertion sort , quick sort , selection sort etc.
Basically GridView represents Data in 2D array. Graphical representation of 2D array is


How to sort Gridview Data in ASP.NET
Lets take an example , Firstly bind GridvView with database using the SqlDataSource. After binding the GridView you should select Enable Sorting Checkbox using ShowSmart Tag.

Enable Sorting Checkbox

Your complete Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default10.aspx.cs" Inherits="Default10" %>

<!DOCTYPE html>

<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" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
                <asp:BoundField DataField="namet" HeaderText="namet" SortExpression="namet" />
                <asp:BoundField DataField="Income" HeaderText="Income" SortExpression="Income" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [footerex]"></asp:SqlDataSource>
 
    </div>
    </form>
</body>
</html>

Output
How to sort Gridview Data in ASP.NET

How to sort Gridview Data in ASP.NET

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved