<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %> <! 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">
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.Data;public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(3000); databind(); } public void databind() { string sql = "SELECT [orderid], [customerid], [shipvia], [shipname] FROM [orders]"; string con = "Data Source=.;Initial Catalog=northwind;User ID=sa;Password=19790601"; SqlConnection mycon = new SqlConnection(con); mycon.Open(); SqlDataAdapter mydt = new SqlDataAdapter(sql, mycon); DataSet ds = new DataSet(); mydt.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); mycon.Close(); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; databind(); }}