打印本文 打印本文 关闭窗口 关闭窗口
C#和SQL数据浏览分页
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3179  更新时间:2007/11/14 13:07:36  文章录入:mintao  责任编辑:mintao
C#和SQL数据浏览分页

如果需要考虑如时间的过滤、其他条件的加入,可以在SQL语句进行编辑,普通的网站,下面的数据浏览分页

就可以了。

aspx代码:

<%@ Page language="c#" Codebehind="StockOrderFormBrower.aspx.cs" AutoEventWireup="false" Inherits="GSP.StockOrderFormBrower" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>

 <HEAD>
  <title>
   用C#和SQL结合进行数据浏览分页
  </title>
  <LINK href="css/main.css" type="text/css" rel="stylesheet">
  <meta http-equiv="Content-Type" content="text/html; charset=GB2312">
  <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
  <meta content="C#" name="CODE_LANGUAGE">
  <meta content="JavaScript" name="vs_defaultClientScript">
 </HEAD>
 
 <body MS_POSITIONING="GridLayout">
  <form id="form1" method="post" runat="server">
   <table id="ShowData" cellSpacing="0" cellPadding="0" align="center" border="0">
    <%ShowData();%><!--输出数据-->
   </table>
   <table align="right">
    <tr>
     <td>
      <%PageLoad_Count();%>
      <INPUT id="first" type="button" value="  |<  " name="first" runat="server"><!--第一页-->
      <INPUT id="prior" type="button" value="  <  " name="prior" runat="server"><!--上一页-->
      <INPUT id="next" type="button" value="  >  " name="next" runat="server"><!--下一页-->
      <INPUT id="last" type="button" value="  >|  " name="last" runat="server"><!--最后一页-->
     </td>
    </tr>
   </table>
  </form>
 </body>

</HTML>

aspx.cs代码:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace ASWBLM
{
 /// <summary>
 /// 
 /// </summary>
 public class UnionInfo : System.Web.UI.Page
 {                                   
  protected System.Web.UI.HtmlControls.HtmlInputButton first;
  protected System.Web.UI.HtmlControls.HtmlInputButton prior;
  protected System.Web.UI.HtmlControls.HtmlInputButton last;
  protected System.Web.UI.HtmlControls.HtmlInputButton next;


  protected static int CurrentPage = 1;//初始化开始页面
  protected static int RowCount = 0 ;//本页有多少条
  private static bool IsPrior = false;//有“前一页”
  private static bool IsNext = false;//有“下一页”
  private static bool IsLast = false;//有“最后一页”
  protected static int not_shown_records=0;//计算未显示记录数
  private static string startID = "";//设置上一页开始ID
  private static string endID = "";//设置下一页结束ID

  private static int page_count = 10;//初始化页面记录数


  private void Page_Load(object sender, System.EventArgs e)
  {   
   // 在此处放置用户代码以初始化页面
   if (!IsPostBack)
   {             
    this.CountRecord().ToString();// 记录总数
    this.Page_Count().ToString();//分页总数   

    Init_Brower();//初始化浏览
   }
  }

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.first.ServerClick += new System.EventHandler(this.first_ServerClick);
   this.prior.ServerClick += new System.EventHandler(this.prior_ServerClick);
   this.next.ServerClick += new System.EventHandler(this.next_ServerClick);
   this.last.ServerClick += new System.EventHandler(this.last_ServerClick);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion                
  
       
  /// <summary>
  /// 显示数据
  /// </summary>
  protected void ShowData()
  {
   DataSet ds = new DataSet();//数据集
   ASWBLM.Include.UnionInfo_Provider _uip = new ASWBLM.Include.UnionInfo_Provider();
   string vSQL = "";
   vSQL = GetSQLCommond(vSQL,startID,endID);
   
   ds = _uip.ShowAllUnionInfo(vSQL);
//取得全部数据的数据集

   try
   { 
    Response.Write("<p align=center>");   
    foreach(DataRow dr in ds.Tables["Table"].Rows)
    {       
     Response.Write("<tr align = center onmouseover = \"this.bgColor = ''''#cccccc''''\" onmouseout = \"this.bgColor='''''''';\">");
     
     Response.Write("<td align=\"left\" width=\"

[1] [2] [3]  下一页

打印本文 打印本文 关闭窗口 关闭窗口