GridView Sorting An Ascending and Descending With Using DataBaseTable in Asp.Net C#

GridView Sorting An Ascending and Descending

Gridview Display  DataBase Table Values Click The Gridview Header  Sorting Ascending and Descending  Order Display  After Click.

                             Download Coding




<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="GridView Display" />


        <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
             DataSourceID="SqlDataSource1" Visible="False">
                <asp:BoundField DataField="id" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                     SortExpression="id" />
              <asp:BoundField DataField="name" HeaderText="NAME" SortExpression="name" />
                <asp:BoundField DataField="country" HeaderText="COUNTRY" SortExpression="country" />
                <asp:BoundField DataField="amount" HeaderText="AMOUNT" SortExpression="amount" />
            <HeaderStyle BackColor="#FF66CC" />
            <RowStyle BackColor="Silver" />
             <AlternatingRowStyle BackColor="#CC33FF" />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:dbcon %>" SelectCommand="SELECT * FROM [country]">


                                 C# CODING

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Default4 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)


    protected void Button1_Click(object sender, EventArgs e)
        GridView1.Visible = true;



First - Add - New Web Form  - Select Button & GridView  From Tool Box

Next - Create DataBase Table  - Add The Details

Next - Select GridView - Right Click - Choose Data Source = New Data Source

Open New Window Form - Select SQL Database  - OK

Next - Select DataBase Name  - Next

Next - Select Table Name - Next 

Next - Click Test Query - Finish

Bind All Field From DataBase Table Fields

Next - Gridview - Right Click - Select Enable Sorting 

Next - GridView - Right Click - Edit Columns - Select Bound Field Header Text  Change

Next  - All Bound Field - Header Text Change 

All Header Text Changed

Next - Gridview Set Property  Visible = False

Next - Button Double Click - Gridview Visible = True

Shown Below  Html Coding  For GridView Sorting

Next - Run[F5] The Program - Sorting Gridview Details 


Post a Comment