1 用存储过程实现分页,除了上一页,下一页,第一页,和末页外还要有go按钮,以及go到那里的文本框。另外还要在Lable显示“当前x页,一共y页”。注意验证控件的使用和 链接存储过程的内容。...
前臺部分
<%@ Page Xlanguage="C#" AutoEventWireup="true" CodeBehind="USEsp_page.aspx.cs" Inherits="12_7" %>
<!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></title>
</head>
<body>
??? <form id="form1" runat="server">
??? <div>
???
??????? <asp:GridView ID="GridView1" runat="server">
??????????? <Columns>
??????????????? <asp:BoundField DataField="sid" HeaderText="行號" />
??????????????? <asp:BoundField DataField="sid" HeaderText="編號" />
??????????????? <asp:BoundField DataField="sname" HeaderText="姓名" />
??????????????? <asp:BoundField DataField="sex" HeaderText="性別" />
??????????????? <asp:BoundField DataField="age" HeaderText="年齡" />
??????????? </Columns>
??????? </asp:GridView>
??????? <br />
??????? <asp:Button ID="btnfirst" runat="server" Text="第一頁" Xοnclick="btnfirst_Click" />
??????? <asp:Button ID="btnprov" runat="server" Text="前一頁" Xοnclick="btnprov_Click" />
??????? <asp:Button ID="btnnext" runat="server" Text="下一頁" Xοnclick="btnnext_Click" />
??????? <asp:Button ID="btnlast" runat="server" Text="最后一頁" Xοnclick="btnlast_Click" />
??????? <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
??????? <asp:TextBox ID="txtpagenumber" runat="server" Width="19px"></asp:TextBox>
??????? <asp:CompareValidator ID="CompareValidator1" runat="server"
??????????? ControlToValidate="txtpagenumber" ErrorMessage="請輸入數字"
??????????? Operator="DataTypeCheck" Type="Integer"></asp:CompareValidator>
??????? <asp:Button ID="btngo" runat="server" Text="GO" Xοnclick="btngo_Click" />
???
??????? <br />
??????? <asp:HiddenField ID="HiddenField1" runat="server" />
??????? <asp:HiddenField ID="HiddenField2" runat="server" />
???
??? </div>
??? </form>
</body>
</html>
后臺部分
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace 12_7
{
??? public partial class USEsp_page : System.Web.UI.Page
??? {
??????? protected void Page_Load(object sender, EventArgs e)
??????? {
??????????? if (!IsPostBack)
??????????? {
??????????????? int pageIndex = 1;
??????????????? BindStudent(pageIndex);
??????????? }
??????? }
??????? private void BindStudent(int pageIndex)
??????? {
??????????? string constr = ConfigurationManager.ConnectionStrings["studentConnectionString"].ConnectionString;
??????????? using (SqlConnection con = new SqlConnection(constr))
??????????? {
??????????????? using (SqlCommand cmd = con.CreateCommand())
??????????????? {
??????????????????? cmd.CommandType = CommandType.StoredProcedure;
??????????????????? string sp_name = "sp_Student_Select_by_Page_rowNumber";
??????????????????? cmd.CommandText = sp_name;
??????????????????? cmd.Parameters.AddWithValue("@pageSize", 3);
??????????????????? SqlParameter p2 = new SqlParameter("@pageCount", System.Data.SqlDbType.Int);
??????????????????? //p2.Direction = ParameterDirection.Output;
??????????????????? //cmd.Parameters.Add(p2);
??????????????????? //cmd.Parameters.AddWithValue("@pageIndex", pageIndex);
??????????????????? cmd.Parameters.Add("@pageCount", System.Data.SqlDbType.Int).Direction = ParameterDirection.Output;
??????????????????? cmd.Parameters.AddWithValue("@pageIndex", pageIndex);
??????????????????? SqlDataAdapter adpter = new SqlDataAdapter(cmd);
??????????????????? DataTable dt = new DataTable();
??????????????????? adpter.Fill(dt);
??????????????????? this.GridView1.DataSource = dt;
??????????????????? this.DataBind();
?????????????????? int pageCount=Convert.ToInt32 (cmd.Parameters["@pageCount"].Value);
?????????????????? this.HiddenField1.Value = pageCount.ToString();
?????????????????? this.HiddenField2.Value = pageIndex.ToString();
??????????????? }
??????????? }
??????? }
??????? protected void btnfirst_Click(object sender, EventArgs e)
??????? {
??????????? this.BindStudent(1);
??????? }
??????? protected void btnlast_Click(object sender, EventArgs e)
??????? {
??????????? this.BindStudent(Convert.ToInt32(this.HiddenField1.Value));
??????? }
??????? protected void btnprov_Click(object sender, EventArgs e)
??????? {
??????????? int index = Convert.ToInt32(this.HiddenField2.Value);
??????????? if (index > 1)
??????????? {
??????????????? index--;
??????????? }
??????????? this.BindStudent(index);
??????? }
??????? protected void btnnext_Click(object sender, EventArgs e)
??????? {
??????????? int pagecount = Convert.ToInt32(this.HiddenField1.Value);
??????????? int index = Convert.ToInt32(this.HiddenField2.Value);
??????????? if (index < pagecount)
??????????? {
??????????????? index++;
??????????? }
??????????? this.BindStudent(index);
??????? }
??????? protected void btngo_Click(object sender, EventArgs e)
??????? {
??????????? this.BindStudent(Convert.ToInt32(txtpagenumber.Text));
??????? }
??? }
}
轉載于:https://www.cnblogs.com/qzc900809/archive/2012/12/07/2807933.html
總結
以上是生活随笔為你收集整理的1 用存储过程实现分页,除了上一页,下一页,第一页,和末页外还要有go按钮,以及go到那里的文本框。另外还要在Lable显示“当前x页,一共y页”。注意验证控件的使用和 链接存储过程的内容。...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: GridControl动态添加 颜色列
- 下一篇: 给定某年日期及该年第一天是星期几然后显示