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

                                              Download

                                   DEMO






HTML CODING


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     
              
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="GridView Display" />
       

       <table><tr><td</td><td>

        <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
             DataSourceID="SqlDataSource1" Visible="False">
          
            <Columns>
                <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" />
            </Columns>
            <HeaderStyle BackColor="#FF66CC" />
            <RowStyle BackColor="Silver" />
             <AlternatingRowStyle BackColor="#CC33FF" />
        </asp:GridView>
      
           </td></tr></table>
      
      
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:dbcon %>" SelectCommand="SELECT * FROM [country]">
        </asp:SqlDataSource>

      
    </div>
    </form>
</body>
</html>

            
                                 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 














0 comments:

Post a Comment