无为清净楼资源网 Design By www.qnjia.com
前台代码:
复制代码 代码如下:
<table style="width: 100%;">
<tr>
<td>
搜索字: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="搜索" OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td>
<div id="divmain" runat="server"> </div>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnFirst" runat="server" Text="首页" OnClick="btnFirst_Click" />
<asp:Button ID="btnPro" runat="server" Text="上一页" OnClick="btnPro_Click" />
<asp:Button ID="btnNext" runat="server" Text="下一页" OnClick="btnNext_Click" />
<asp:Button ID="btnLast" runat="server" Text="末页" OnClick="btnLast_Click" />
<asp:Label ID="labCountPage" runat="server"></asp:Label>
<asp:Label ID="labpage" runat="server"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Width="16px"></asp:TextBox>
<asp:Button ID="btnGo" runat="server" OnClick="btnGo_Click" Text="Go" />
</td>
</tr>
</table>
后台代码:
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["pageIndex"] = 1;
dataPage();
}
}
private void dataPage()
{
string constr = @"data source=.;initial catalog=News;user id=sa;password=111111;";
SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
#region 用存储过程实现数据分页效果
//cmd.CommandType = CommandType.StoredProcedure;
//cmd.CommandText = "Pro_SelectNewsPage";
//cmd.Parameters.AddWithValue("@pageIndex", Convert.ToInt32(ViewState["pageIndex"]));
//cmd.Parameters.AddWithValue("@pageSize", 3);
//SqlParameter parm = new SqlParameter("@count", SqlDbType.Int);
//cmd.Parameters.Add(parm);
//parm.Direction = ParameterDirection.Output;
#endregion
#region 传递SQl语句实现分页并对搜索实现分页默认显示两条记录
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select top 2 * from (select * from T_News where NewsTitle like @title) as t where t.Id not in(select top ((@pageIndex-1)*2) t.Id from (select * from T_News where NewsTitle like @title) as t) order by t.Id";
cmd.Parameters.AddWithValue("@pageIndex", Convert.ToInt32(ViewState["pageIndex"]));
cmd.Parameters.AddWithValue("@title","%"+TextBox1.Text.Trim()+"%");
#endregion
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
//ViewState["pageCount"] = parm.Value;
cmd.CommandText = "select count(*) from T_News where NewsTitle like @titles";
cmd.Parameters.AddWithValue("@titles", "%" + TextBox1.Text.Trim() + "%");
int sum = Convert.ToInt32(cmd.ExecuteScalar());
if (sum % 2 == 0)
{
ViewState["pageCount"] = sum/2;
}
else
{
ViewState["pageCount"] = sum / 2 + 1;
}
conn.Close();
conn.Dispose();
StringBuilder sb = new StringBuilder();
sb.Append("<table>");
foreach (DataRow row in dt.Rows)
{
sb.Append("<tr><td>"+row["NewsTitle"].ToString()+"</td>");
sb.Append("<td>" + row["NewsContent"].ToString() + "</td>");
sb.Append("<td>" + row["CreateTime"].ToString() + "</td></tr>");
}
sb.Append("</table>");
divmain.InnerHtml = sb.ToString();
labCountPage.Text = "总共" + ViewState["pageCount"] + "页";
labpage.Text = "当前第" + ViewState["pageIndex"] + "页";
}
protected void Button1_Click(object sender, EventArgs e)
{
ViewState["pageIndex"] = "1";
dataPage();
}
protected void btnFirst_Click(object sender, EventArgs e)
{
ViewState["pageIndex"] = "1";
dataPage();
}
protected void btnPro_Click(object sender, EventArgs e)
{
int index = Convert.ToInt32(ViewState["pageIndex"]);
index--;
if (index >= 1)
{
ViewState["pageIndex"] = index;
dataPage();
}
}
protected void btnNext_Click(object sender, EventArgs e)
{
int index = Convert.ToInt32(ViewState["pageIndex"]);
index++;
if (index <= Convert.ToInt32(ViewState["pageCount"]))
{
ViewState["pageIndex"] = index;
dataPage();
}
}
protected void btnLast_Click(object sender, EventArgs e)
{
ViewState["pageIndex"] =ViewState["pageCount"];
dataPage();
}
protected void btnGo_Click(object sender, EventArgs e)
{
int i=Convert.ToInt32(TextBox2.Text);
if (i > 0 && i <= Convert.ToInt32(ViewState["pageCount"]))
{
ViewState["pageIndex"] = i;
dataPage();
}
}
复制代码 代码如下:
<table style="width: 100%;">
<tr>
<td>
搜索字: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="搜索" OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td>
<div id="divmain" runat="server"> </div>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnFirst" runat="server" Text="首页" OnClick="btnFirst_Click" />
<asp:Button ID="btnPro" runat="server" Text="上一页" OnClick="btnPro_Click" />
<asp:Button ID="btnNext" runat="server" Text="下一页" OnClick="btnNext_Click" />
<asp:Button ID="btnLast" runat="server" Text="末页" OnClick="btnLast_Click" />
<asp:Label ID="labCountPage" runat="server"></asp:Label>
<asp:Label ID="labpage" runat="server"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Width="16px"></asp:TextBox>
<asp:Button ID="btnGo" runat="server" OnClick="btnGo_Click" Text="Go" />
</td>
</tr>
</table>
后台代码:
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["pageIndex"] = 1;
dataPage();
}
}
private void dataPage()
{
string constr = @"data source=.;initial catalog=News;user id=sa;password=111111;";
SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
#region 用存储过程实现数据分页效果
//cmd.CommandType = CommandType.StoredProcedure;
//cmd.CommandText = "Pro_SelectNewsPage";
//cmd.Parameters.AddWithValue("@pageIndex", Convert.ToInt32(ViewState["pageIndex"]));
//cmd.Parameters.AddWithValue("@pageSize", 3);
//SqlParameter parm = new SqlParameter("@count", SqlDbType.Int);
//cmd.Parameters.Add(parm);
//parm.Direction = ParameterDirection.Output;
#endregion
#region 传递SQl语句实现分页并对搜索实现分页默认显示两条记录
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select top 2 * from (select * from T_News where NewsTitle like @title) as t where t.Id not in(select top ((@pageIndex-1)*2) t.Id from (select * from T_News where NewsTitle like @title) as t) order by t.Id";
cmd.Parameters.AddWithValue("@pageIndex", Convert.ToInt32(ViewState["pageIndex"]));
cmd.Parameters.AddWithValue("@title","%"+TextBox1.Text.Trim()+"%");
#endregion
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
//ViewState["pageCount"] = parm.Value;
cmd.CommandText = "select count(*) from T_News where NewsTitle like @titles";
cmd.Parameters.AddWithValue("@titles", "%" + TextBox1.Text.Trim() + "%");
int sum = Convert.ToInt32(cmd.ExecuteScalar());
if (sum % 2 == 0)
{
ViewState["pageCount"] = sum/2;
}
else
{
ViewState["pageCount"] = sum / 2 + 1;
}
conn.Close();
conn.Dispose();
StringBuilder sb = new StringBuilder();
sb.Append("<table>");
foreach (DataRow row in dt.Rows)
{
sb.Append("<tr><td>"+row["NewsTitle"].ToString()+"</td>");
sb.Append("<td>" + row["NewsContent"].ToString() + "</td>");
sb.Append("<td>" + row["CreateTime"].ToString() + "</td></tr>");
}
sb.Append("</table>");
divmain.InnerHtml = sb.ToString();
labCountPage.Text = "总共" + ViewState["pageCount"] + "页";
labpage.Text = "当前第" + ViewState["pageIndex"] + "页";
}
protected void Button1_Click(object sender, EventArgs e)
{
ViewState["pageIndex"] = "1";
dataPage();
}
protected void btnFirst_Click(object sender, EventArgs e)
{
ViewState["pageIndex"] = "1";
dataPage();
}
protected void btnPro_Click(object sender, EventArgs e)
{
int index = Convert.ToInt32(ViewState["pageIndex"]);
index--;
if (index >= 1)
{
ViewState["pageIndex"] = index;
dataPage();
}
}
protected void btnNext_Click(object sender, EventArgs e)
{
int index = Convert.ToInt32(ViewState["pageIndex"]);
index++;
if (index <= Convert.ToInt32(ViewState["pageCount"]))
{
ViewState["pageIndex"] = index;
dataPage();
}
}
protected void btnLast_Click(object sender, EventArgs e)
{
ViewState["pageIndex"] =ViewState["pageCount"];
dataPage();
}
protected void btnGo_Click(object sender, EventArgs e)
{
int i=Convert.ToInt32(TextBox2.Text);
if (i > 0 && i <= Convert.ToInt32(ViewState["pageCount"]))
{
ViewState["pageIndex"] = i;
dataPage();
}
}
标签:
table,分页
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年11月14日
2024年11月14日
- 黄乙玲1988-无稳定的爱心肝乱糟糟[日本东芝1M版][WAV+CUE]
- 群星《我们的歌第六季 第3期》[320K/MP3][70.68MB]
- 群星《我们的歌第六季 第3期》[FLAC/分轨][369.48MB]
- 群星《燃!沙排少女 影视原声带》[320K/MP3][175.61MB]
- 乱斗海盗瞎6胜卡组推荐一览 深暗领域乱斗海盗瞎卡组分享
- 炉石传说乱斗6胜卡组分享一览 深暗领域乱斗6胜卡组代码推荐
- 炉石传说乱斗本周卡组合集 乱斗模式卡组最新推荐
- 佟妍.2015-七窍玲珑心【万马旦】【WAV+CUE】
- 叶振棠陈晓慧.1986-龙的心·俘虏你(2006复黑限量版)【永恒】【WAV+CUE】
- 陈慧琳.1998-爱我不爱(国)【福茂】【WAV+CUE】
- 咪咕快游豪礼放送,百元京东卡、海量欢乐豆就在咪咕咪粉节!
- 双11百吋大屏焕新“热”,海信AI画质电视成最大赢家
- 海信电视E8N Ultra:真正的百吋,不止是大!
- 曾庆瑜1990-曾庆瑜历年精选[派森][WAV+CUE]
- 叶玉卿1999-深情之选[飞图][WAV+CUE]