2个回答
展开全部
Default.aspx.cs页面:
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using UcfarDB;
public partial class _Default : System.Web.UI.Page
{
DBHelper db = new DBHelper();
Pager pager = new Pager();
public string sql;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
InitData(1);
}
private void InitData(int pageindex)
{
//int pageCount;//绑定方法一
//int itemCount;//绑定方法一
string hanzi = this.TextBox1.Text.Trim().ToString();
if (hanzi != "")
{
sql = "select * from DicData WHERE HANZI = '" + hanzi + "' ";
this.UcfarPager1.RecordCount = pager.CreateCountSQL(sql);//绑定方法二
}
else
{
sql = "select * from DicData ";
this.UcfarPager1.RecordCount = pager.CreateCountSQL(sql);//绑定方法二
}
//Pager.OrderByStruct order = new Pager.OrderByStruct("hanzi", Pager.Directions.ASC);//绑定方法一
//DataTable ds = pager.GetData_SQL2005(sql, pageindex, UcfarPager1.PageSize, out pageCount, out itemCount, order);//绑定方法一
//this.UcfarPager1.RecordCount = itemCount;//绑定方法一
//this.GridView1.DataSource = pager.GetData_SQL2005(sql, pageindex, UcfarPager1.PageSize, out pageCount, out itemCount, order);//绑定方法一
DataTable dt = db.ExecuteDataSet(sql, UcfarPager1.PageSize * (pageindex-1), UcfarPager1.PageSize).Tables[0];
this.GridView1.DataSource =dt ;//绑定方法二
GridView1.DataBind();
}
protected void UcfarPager1_PageChanged(object sender, EventArgs e)
{
InitData(UcfarPager1.CurrentPageIndex);
}
protected void Button1_Click(object sender, EventArgs e)
{
InitData(1);
}
}
Default.aspx页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="UcfarPager" Namespace="UcfarPager" TagPrefix="cc1" %>
<!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>
<style type="text/css">
*{font-size:12px;font-family:verdana;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="margin-top:10px;">
汉字:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1"
runat="server" Text="查询" OnClick="Button1_Click" />
</div>
<asp:GridView ID="GridView1" runat="server" BackColor="White" Width="600px"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
ForeColor="Black" GridLines="Vertical">
<FooterStyle BackColor="#CCCC99" />
<RowStyle BackColor="#F7F7DE" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<br />
<cc1:UcfarPager ID="UcfarPager1" runat="Server" MainTableStyle="text-align:left;"
onpagechanged="UcfarPager1_PageChanged" PageSize="15" NavigatePreviousText="上一页" NavigateNextText="下一页" >
</cc1:UcfarPager>
</form>
</body>
</html>
相信这些代码对你肯定有一点帮助!
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using UcfarDB;
public partial class _Default : System.Web.UI.Page
{
DBHelper db = new DBHelper();
Pager pager = new Pager();
public string sql;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
InitData(1);
}
private void InitData(int pageindex)
{
//int pageCount;//绑定方法一
//int itemCount;//绑定方法一
string hanzi = this.TextBox1.Text.Trim().ToString();
if (hanzi != "")
{
sql = "select * from DicData WHERE HANZI = '" + hanzi + "' ";
this.UcfarPager1.RecordCount = pager.CreateCountSQL(sql);//绑定方法二
}
else
{
sql = "select * from DicData ";
this.UcfarPager1.RecordCount = pager.CreateCountSQL(sql);//绑定方法二
}
//Pager.OrderByStruct order = new Pager.OrderByStruct("hanzi", Pager.Directions.ASC);//绑定方法一
//DataTable ds = pager.GetData_SQL2005(sql, pageindex, UcfarPager1.PageSize, out pageCount, out itemCount, order);//绑定方法一
//this.UcfarPager1.RecordCount = itemCount;//绑定方法一
//this.GridView1.DataSource = pager.GetData_SQL2005(sql, pageindex, UcfarPager1.PageSize, out pageCount, out itemCount, order);//绑定方法一
DataTable dt = db.ExecuteDataSet(sql, UcfarPager1.PageSize * (pageindex-1), UcfarPager1.PageSize).Tables[0];
this.GridView1.DataSource =dt ;//绑定方法二
GridView1.DataBind();
}
protected void UcfarPager1_PageChanged(object sender, EventArgs e)
{
InitData(UcfarPager1.CurrentPageIndex);
}
protected void Button1_Click(object sender, EventArgs e)
{
InitData(1);
}
}
Default.aspx页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="UcfarPager" Namespace="UcfarPager" TagPrefix="cc1" %>
<!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>
<style type="text/css">
*{font-size:12px;font-family:verdana;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="margin-top:10px;">
汉字:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1"
runat="server" Text="查询" OnClick="Button1_Click" />
</div>
<asp:GridView ID="GridView1" runat="server" BackColor="White" Width="600px"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
ForeColor="Black" GridLines="Vertical">
<FooterStyle BackColor="#CCCC99" />
<RowStyle BackColor="#F7F7DE" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<br />
<cc1:UcfarPager ID="UcfarPager1" runat="Server" MainTableStyle="text-align:left;"
onpagechanged="UcfarPager1_PageChanged" PageSize="15" NavigatePreviousText="上一页" NavigateNextText="下一页" >
</cc1:UcfarPager>
</form>
</body>
</html>
相信这些代码对你肯定有一点帮助!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询