前言:
今天咱们对“aspnet获取cpuid”大体比较讲究,各位老铁们都需要了解一些“aspnet获取cpuid”的相关文章。那么小编在网摘上汇集了一些关于“aspnet获取cpuid””的相关资讯,希望朋友们能喜欢,看官们一起来了解一下吧!查询数据后,将数据分页显示
一、前台页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="querypage.aspx.cs" Inherits="guolei.Web.querypage" %> <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ";> <html xmlns=";> <head id="Head1" runat="server"> <title>Title</title> <style type="text/css"> *{margin:0;padding:0;} table.gridtable{ width:80%; font-family: verdana,arial,sans-serif; font-size:11px; color:#333333; border-width: 1px; border-color: #666666; border-collapse: collapse;}table.gridtable th { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666;}table.gridtable td { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #ffffff; text-align:center;} </style></head><body> <form id="form1" runat="server"> <asp:TextBox ID="txtKeywords" runat="server" CssClass="keyword" /> <asp:LinkButton ID="lbtnSearch" runat="server" CssClass="btn-search" onclick="btnSearch_Click">查询</asp:LinkButton> <asp:Button ID="btn_all" runat="server" OnClick="btn_all_Click" Text="显示所有" /> <asp:Button ID="btn_empty" runat="server" OnClick="btn_empty_Click" Text="清空" /> <div> <asp:Repeater ID="RepList1" runat="server"> <HeaderTemplate> <table class="gridtable"> <thead> <tr> <th style="width: 100px;"> 顺序号 </th><th style="width: 100px;"> ID </th> <th style="width: 270px;"> 标题 </th> <th style="width: 270px;"> 时间 </th> </tr> </thead> </HeaderTemplate> <ItemTemplate> <tbody> <tr> <td> <%# (this.AspNetPager1.CurrentPageIndex - 1) * this.AspNetPager1.PageSize + Container.ItemIndex + 1%></td> <td> <%#Eval("id")%> </td> <td> <%#Eval("title")%> </td> <td> <%#Eval("add_time")%> </td> </tr> </ItemTemplate> <FooterTemplate> </tbody> </table> </FooterTemplate> </asp:Repeater> </div> <div class="pull-right"> <webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="100%" NumericButtonCount="6" UrlPaging="true" CustomInfoHTML="总计%RecordCount%条记录,共%PageCount%页"ShowCustomInfoSection="left" FirstPageText="首页" LastPageText="末页" NextPageText="下页" PrevPageText="上页" Font-Names="Arial" BackColor="#F8B500" AlwaysShow="true" SubmitButtonStyle="botton" OnPageChanged="AspNetPager1_PageChanged" PageSize="15"> </webdiyer:AspNetPager> </div> </form></body></html>
二、后台代码
protected void Page_Load(object sender, EventArgs e) { string keywords = Request.QueryString["keywords"]; AspNetPager1.RecordCount = new DAL.title().GetCount(keywords); } //查询按钮 protected void btnSearch_Click(object sender, EventArgs e) { Response.Redirect("querypage.aspx?keywords=" + txtKeywords.Text); } //显示全部 protected void btn_all_Click(object sender, EventArgs e) { Response.Redirect("querypage.aspx"); } //清空protected void btn_empty_Click(object sender, EventArgs e) { txtKeywords.Text = ""; this.RepList1.Controls.Clear();//清空当前内容 RepList1.DataSource = string.Empty; RepList1.DataBind(); AspNetPager1.RecordCount = 0; } protected void AspNetPager1_PageChanged(object src, EventArgs e) { string keywords = Request.QueryString["keywords"]; txtKeywords.Text = keywords; RepList1.DataSource = new DAL.title().SelectbyPage(keywords,AspNetPager1.StartRecordIndex.ToString(), AspNetPager1.EndRecordIndex.ToString()); RepList1.DataBind(); }
三、DAL代码
//得到条件查询后的记录行数 public int GetCount(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(*) from title where"); strSql.Append(CombSqlTxt(strWhere)); return Convert.ToInt32(new SqlHelper().ExecuteScalar(strSql.ToString(), CommandType.Text)); } // 组合SQL查询语句========================== protected string CombSqlTxt(string _keywords) { StringBuilder strTemp = new StringBuilder(); if (!string.IsNullOrEmpty(_keywords)) { strTemp.Append(" title like '%" + _keywords + "%'"); } else { strTemp.Append(" 1=1"); } return strTemp.ToString(); } //带有查询条件的分页 public DataTable SelectbyPage(string strWhere, string startIndex, string endIndex) //当前页的首条页码参数starIndex和最后页码参数endIndex { StringBuilder strSql = new StringBuilder(); strSql.Append("with temptbl as ( SELECT ROW_NUMBER() OVER (ORDER BY id desc)AS Row, * from title where "); strSql.Append(CombSqlTxt(strWhere)); //添加条件语句 strSql.Append(") SELECT * FROM temptbl where Row between @startIndex and @endIndex"); SqlParameter[] sqlParameters = { new SqlParameter("@startIndex", startIndex), new SqlParameter("@endIndex",endIndex)}; DataTable dt = new SqlHelper().ExecuteQuery(strSql.ToString(), sqlParameters, CommandType.Text); return dt; }
四、效果图
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #aspnet获取cpuid