ADO Net Database ASP.Net Tutorial

<%@ Page language="c#"  Inherits="DataViewSort" CodeFile="Default.aspx.cs" %>


  
    
      Original order

      

      
      

      Sort = "LastName"

      

      
      

      Sort = "FirstName"

      

      
    
  

File: Default.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class DataViewSort : System.Web.UI.Page
{
  protected void Page_Load(object sender, System.EventArgs e)
  {
    string connectionString = "Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI";
    SqlConnection con = new SqlConnection(connectionString);
    string sql = "SELECT TOP 5 EmployeeID, TitleOfCourtesy, LastName, FirstName FROM Employees";
    SqlDataAdapter da = new SqlDataAdapter(sql, con);
    DataSet ds = new DataSet();
    da.Fill(ds, "Employees");
    Datagrid1.DataSource = ds.Tables["Employees"];
    DataView view2 = new DataView(ds.Tables["Employees"]);
    view2.Sort = "LastName";
    Datagrid2.DataSource = view2;
    DataView view3 = new DataView(ds.Tables["Employees"]);
    view3.Sort = "FirstName";
    Datagrid3.DataSource = view3;
    this.DataBind();
  }
}