找不到哪里出错了,而且总共的数据绝对不止一个pagesize 
希望大家能帮忙,谢谢~

解决方案 »

  1.   

    代码如下:
    --------OnlineBook.aspx---------------
     <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="OnlineBook.Index" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <html xmlns="http://www.w3.org/1999/xhtml">
     <head runat="server">
         <title></title>
     </head>
     <body>
         <form id="form1" runat="server">
         <div>
                <div style="width:300px;float:right">
                 <asp:Label ID="label2" runat="server" Text="用户名:"></asp:Label>
                 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
                 <asp:Label ID="label3" runat="server" Text="密码: "></asp:Label>
                 <asp:TextBox ID="password" runat="server" TextMode="Password" Width="138px"></asp:TextBox>
                         </div>
             <div style="width:300px; display:inline">
                 &nbsp;<asp:Label ID="label1" runat="server" Text="节目查询"></asp:Label>
                 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="查询" />
                 <asp:HyperLink ID="HyperLink1" runat="server">高级搜索</asp:HyperLink>
             </div>     </div>
         <div>
             <asp:DataGrid ID="dgcom" Style="z-index: 111; left: 138px; position: absolute; top: 218px"
                 Width="920px" BackColor="white" Height="182px" BorderColor="black" BorderStyle="None" AllowPaging="True"   AllowCustomPaging="true"
                 PageSize="5"  BorderWidth="1" CellPadding="3"   OnPageIndexChanged="MyDataGrid_Page"
                 AutoGenerateColumns="false" runat="server">
               <%--  <SelectedItemStyle Font-Bold="true" ForeColor="blue" BackColor="Black"></SelectedItemStyle>
         <AlternatingItemStyle BackColor="Blue"></AlternatingItemStyle>
                <ItemStyle ForeColor="Beige" BackColor="Blue"></ItemStyle>--%>
                 <HeaderStyle Font-Bold="true" ForeColor="Beige" BackColor="black"></HeaderStyle>
                <%-- <FooterStyle ForeColor="#4A3C8C" BackColor="AliceBlue"></FooterStyle>--%>
                 <Columns>
                     <asp:BoundColumn HeaderText="书名" DataField="bookname" />
                     <asp:BoundColumn HeaderText="作者" DataField="author" />
                     <asp:BoundColumn HeaderText="出版社" DataField="address" />
                     <asp:BoundColumn HeaderText="ISBN号" DataField="booknumber" />
                     <asp:BoundColumn HeaderText="原价" DataField="yprice" />
                     <asp:BoundColumn HeaderText="折扣" DataField="zhekou" />
                 </Columns>
               <PagerStyle HorizontalAlign="Right" ForeColor="DarkGreen" BackColor="Red" Mode="NumericPages">
                </PagerStyle>
             </asp:DataGrid>
                  <asp:Label ID="label4" 
            Style="z-index: 114; left: 139px; position: absolute; top: 197px; width: 920px; height: 19px;" 
            BackColor="InactiveCaptionText" BorderColor="black"
                 BorderStyle="None" PageSize="5" GridLines="Horizontal" BorderWidth="1" CellPadding="3"
                 AutoGenerateColumns="false" OnItemCommand="Grid_CartCommand" 
                runat="server" Text="计算机类"></asp:Label>
         </form>
     </body>
     </html>
     
      

  2.   

    ------OnlineBook.aspx.cs---------
     using System;
     using System.Collections.Generic;
     using System.Web;
     using System.Web.UI;
     using System.Web.UI.WebControls;
     using System.Configuration;
     using System.Data.SqlClient;
     using System.Data;
     using System.Collections;
     
    namespace OnlineBook
     {
         public partial class Index : System.Web.UI.Page
         {
             //DataSet getbata;
             protected void Page_Load(object sender, EventArgs e)
             {
                 if (!Page.IsPostBack)
                 {
                     BindGrid();
     
                }
                        }
     
            protected void Button1_Click(object sender, EventArgs e)
             {
     
            }
             public void BindGrid() {
                 
                 dgcom.DataSource = CreateDataSource();
                 dgcom.VirtualItemCount = 16;
                 dgcom.DataBind();
             
             }
     
          public void MyDataGrid_Page(Object sender, DataGridPageChangedEventArgs e)
             {
                
                 dgcom.CurrentPageIndex = e.NewPageIndex;
                 BindGrid();
           
             }
     
          ICollection CreateDataSource() {
     
              string connectionstring = ConfigurationSettings.AppSettings["connectionstring"].ToString().Trim();//web.config的配置,在下面;
               string sql = "select * from bookinfo where T_type='计算机'";
               SqlConnection conn = new SqlConnection(connectionstring);
               //SqlCommand mycmd = new SqlCommand(sql, conn);
               conn.Open();
               SqlDataAdapter da = new SqlDataAdapter(sql, conn);
               DataTable bata1 = new DataTable();
               da.Fill(bata1);
               DataView dv = new DataView(bata1);
               return dv;
           } 
        }
     }
     
      

  3.   

    ------web.config--------
     <?xml version="1.0" encoding="utf-8"?>
     
    <configuration>
         <system.web>
             <!-- 
                设置 compilation debug="true" 可将调试符号插入
                 已编译的页面中。但由于这会 
                影响性能,因此只在开发过程中将此值 
                设置为 true。
             -->
             <compilation defaultLanguage="C#" debug="true">
     
            </compilation>
             <!--
                 通过 <authentication> 节可以配置 ASP.NET 用来 
                识别进入用户的
                 安全身份验证模式。 
            -->
             <authentication mode="Windows" />
           <customErrors mode="RemoteOnly" />
           <authorization>
             <allow  users="*"/>  <!--允许所有用户-->
           </authorization>
             <!--
                 如果在执行请求的过程中出现未处理的错误,
                 则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
                 开发人员通过该节可以配置
                 要显示的 html 错误页
                 以代替错误堆栈跟踪。
     
            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                 <error statusCode="403" redirect="NoAccess.htm" />
                 <error statusCode="404" redirect="FileNotFound.htm" />
             </customErrors>
             -->
           <globalization  requestEncoding="utf-8" responseEncoding="utf-8"/>   
           <!--全球化
           此节设置应用程序的全球化设置-->
         </system.web>   <appSettings>
    //数据库字符串配置
     <add key="connectionstring" value="server=localhost;uid=sa;pwd=sql2005;database=shop"/>
       </appSettings> </configuration>
     
      

  4.   

    你根本就没写分页。。还能分页吗?看看这里  http://www.cnblogs.com/sayu115/archive/2007/10/12/922115.html
      

  5.   

    你看看自己的SQL语句 根本就没分页
    你只是在分页事件里重新绑定了下数据源 没用 你百度下aspnetpage
      

  6.   

    我也上网找了很多资料,都说加AllowPaging="True" AllowCustomPaging="true"和分页处理事件OnPageIndexChanged和设置VirtualItemCount,就可以完成?可就是无法分页
     能给我个简单的分页例子么,谢谢
      

  7.   

    你应该是
    da.Fill(bata1,2,20,"bookinfo");这里的2,20代码你的页码,不同的页面要进行变化
      

  8.   

    你检查一下你的SQL语句,分页那儿的
      

  9.   

    http://www.cnblogs.com/xiaobaigang/articles/824011.html
      

  10.   

    http://www.cnblogs.com/suibing/archive/2005/04/05/132650.html
      

  11.   

    你可以试试AspNetPager
      

  12.   

    SQL语句:
    ----------------------------
    SELECT *
    FROM 
    (
        SELECT BOOKNAME,ROW_NUMBER() OVER (ORDER BY BOOKNAME) AS SERIALNO
        FROM  BOOKINFO
        WHERE T_TYPE = '计算机'
    ) A
    WHERE SERIALNO BETWEEN #STARTNUM# AND #ENDNUM# 
    ----------------------------
    其中#STARTNUM#和#ENDNUM#,你可根据当前页码和每页记录行数计算获得