DataGrid传统分页方式[1]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 wsqsoft 的 blog

此分页方式与传统asp分页方式相仿.

datagridpage.aspx

<%@ page language="c#" codebehind="datagridpage.aspx.cs" autoeventwireup="false" inherits="netcrm.datagridpage" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
 <head>
  <title>datagridpage</title>
  <meta name="generator" content="microsoft visual studio .net 7.1">
  <meta name="code_language" content="c#">
  <meta name="vs_defaultclientscript" content="javascript">
  <meta name="vs_targetschema" content="http://schemas.microsoft.com/intellisense/ie5">
 </head>
 <body ms_positioning="gridlayout">
  <form id="form1" method="post" runat="server">
   <asp:datagrid id="datagrid1" runat="server" alternatingitemstyle-backcolor="#eeeeee" headerstyle-backcolor="#aaaadd"
    font-size="8pt" font-name="verdana" cellpadding="3" borderwidth="1px" bordercolor="black"
    pagerstyle-horizontalalign="right" pagerstyle-mode="numericpages"
    pagesize="5" font-names="verdana" width="100%">
    <alternatingitemstyle backcolor="#eeeeee"></alternatingitemstyle>
    <headerstyle backcolor="#aaaadd"></headerstyle>
    <pagerstyle horizontalalign="right" mode="numericpages"></pagerstyle>
   </asp:datagrid>
  </form>
  <table cellspacing="0" cellpadding="1" width="100%" bgcolor="#aaaadd" border="0">
   <tbody>
    <tr>
     <td>
      <table cellspacing="0" cellpadding="4" width="100%" bgcolor="#fef8e2" border="0">
       <tbody>
        <tr>
         <td class="m" nowrap align="center"><asp:literal id="literal1" runat="server"></asp:literal></td>
        </tr>
        <tr>
         <td class="c" nowrap align="center"><asp:literal id="literal2" runat="server"></asp:literal></td>
        </tr>
       </tbody>
      </table>
     </td>
    </tr>
   </tbody>
  </table>
 </body>
</html>

datagridpage.aspx.cs

using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.data.sqlclient;
using system.drawing;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;

namespace netcrm
{
 /// <summary>
 /// datagridpage 的摘要说明。
 /// </summary>
 public class datagridpage : system.web.ui.page
 {
  protected system.web.ui.webcontrols.literal literal1;
  protected system.web.ui.webcontrols.literal literal2;
  protected system.web.ui.webcontrols.datagrid datagrid1;
 
  private void page_load(object sender, system.eventargs e)
  {
   // 在此处放置用户代码以初始化页面
   if(!ispostback)
   {
    bindgrid();
   }
  }

  private void bindgrid()
  {
   string connstring = "server=.;database=northwind;user id=sa;password=;";
   string sql="select * from orders";
   sqlconnection conn = new  sqlconnection(connstring);
   conn.open();
   dataset ds = new dataset();
   sqldataadapter sqladapter = new sqldataadapter(sql,conn);
   sqladapter.fill(ds,"users");

   dataview dataview = new dataview();
   dataview = ds.tables[0].defaultview;

   datagrid1.datasource = ds.tables[0].defaultview;
   datagrid1.databind();
   
   
   string cpage;
   int pagesize = 10;
   int currentpage;
   int pagecount;

本文关键:DataGrid 分页
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top