<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "pagechanging.aspx.cs " Inherits= "pagechanging " %>
<!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 " >
<head runat= "server ">
<title> Untitled Page </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<table>
<tr>
<td>
<asp:Button ID= "bt1 " runat=server Text= "查询 " OnClick= "bt1_Click " />
</td>
</tr>
<tr>
<td>
<asp:GridView ID= "gridview1 " AllowPaging=true runat=server AutoGenerateColumns=false OnPageIndexChanging= "gridview1_PageIndexChanging " PageSize= "5 ">
<Columns>
<asp:BoundField HeaderText= "名称 " DataField= "job_desc " />
<asp:BoundField HeaderText= "最小数 " DataField= "min_lvl " />
<asp:BoundField HeaderText= "最大数 " DataField= "max_lvl " />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class pagechanging : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gridview1.DataBind();
}
}
protected void bt1_Click(object sender, EventArgs e)
{
SqlConnection con = DB.createConnection();