.net搜索查询并实现分页实例

时间:2021-05-28

前台:
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="分页.aspx.cs" Inherits="分页练习.分页" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://mandText = "SELECT COUNT(*) FROM T_News WHERE NewsTitle LIKE @newskey OR NewsContent LIKE @newskey";
cmd.Parameters.AddWithValue("@newskey", "%" + txtKey.Text + "%");
conn.Open();
int totalcount = Convert.ToInt32(cmd.ExecuteScalar());
if (totalcount % pagesize == 0)
{
ViewState["pagelastindex"] = totalcount / pagesize;
}
else
{
ViewState["pagelastindex"] = totalcount / pagesize + 1;
}
cmd.Dispose();
conn.Dispose();
}
//第一页
protected void btnFirst_Click(object sender, EventArgs e)
{
ViewState["pageindex"] = 1;
LoadData();
}
//上一页
protected void btnBefore_Click(object sender, EventArgs e)
{

int pageindex = Convert.ToInt32(ViewState["pageindex"]);
if (pageindex > 1)
{
pageindex--;
ViewState["pageindex"] = pageindex;
LoadData();
}
}
//下一页
protected void btnNext_Click(object sender, EventArgs e)
{
int pageindex = Convert.ToInt32(ViewState["pageindex"]);
if (pageindex < Convert.ToInt32(ViewState["pagelastindex"]))
{
pageindex++;
ViewState["pageindex"] = pageindex;
LoadData();
}
}
//最后一页
protected void btnLast_Click(object sender, EventArgs e)
{
ViewState["pageindex"] = ViewState["pagelastindex"];
LoadData();
}
protected void btnQuery_Click(object sender, ImageClickEventArgs e)
{
Count();
LoadData();
}
}
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章