是要写事件的
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;

}

解决方案 »

  1.   

    csqok(csq) 
    不行阿,还是只有文字,没有链接。
      

  2.   

    我没绑定过datareader,不知道有没有区别
    我是绑定Table,和DataSet应该是一样的
    然后事件里PageIndexChanged加上事件,代码象刚才所写,
    但不知道对你是否适用
      

  3.   

    你的记录有三十条吗,如果没有就没有链接
    另把那个AllowCustomPaging =True  改成false试一下
      

  4.   

    我的记录有100多条阿,
    确实取到了这么多记录,
    用table怎么绑定阿?
    给个实例阿
      

  5.   

    如果你想用它自带的分页,你到属性里去设置,不用允许自定义分页就允许分页就行了,设置好之后,要写分页的事件,你的数据源最好是用DATATABLE。
      

  6.   

    DataTable table = new DataTable();
    SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["你的打开方式"]);
    SqlDataAdapter wAdapter = new SqlDataAdapter();myConnection.Open();
    SqlCommand wCommand = new SqlCommand(SearchString, myConnection);
    wCommand.CommandType = CommandType.Text;
    wAdapter.SelectCommand = wCommand;
    // Create and Fill the DataSet
    wAdapter.Fill(table);
    myConnection.Close();
    //前面是取数据的DataGrid1.DataSource = table;
    DataGrid1.DataBind();
      

  7.   

    Dim myad As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(sql, myconn.sqlconn)
            Dim ds As New DataSet()
            myad.Fill(ds, "t001")
            DataGrid1.DataSource = ds.table("t001").faultview           
            DataGrid1.DataBind()
      

  8.   

    还是不行阿,只是显示文字,没有链接,
    我改成40 就只显示40条,改成10就只显示10条,
    上一页和下一页都没有链接。如果把 AllowCustomPaging =True  去掉就会出错
    类型“DataGridLinkButton”的控件“Grid__ctl14__ctl1”必须放在具有 runat=server 的窗体标记内。  <asp:DataGrid AllowPaging="True" PageSize="10"  PagerStyle-PrevPageText='上一页' PagerStyle-NextPageText='下一页' id="Grid" Width="100%" runat="server" BorderColor="#CCCCCC" ItemStyle-Height="30" AlternatingItemStyle-BackColor="#f2f2f2" HeaderStyle-BackColor="#f7f7f7" ShowFooter="True"  OnPageIndexChanged ="Grid_PageIndexChanged">
    这样写有什么问题吗??
      

  9.   

    使用DataReader就必须使用自定义分页了,你应该隐藏分页行,然后自己添加
    LinkButton来取数据,可以参考一下这个
    http://www.csdn.net/Expert/TopicView1.asp?id=964969
      

  10.   

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkWalkthroughDisplayingDataInListBoxesOnWebFORMsPage.asp
    这个比较简单
      

  11.   

    如果你要使用 DataReader 做分页
    只能是自定义分页 即:
    AllowCustomPaging =True  做自定义分页一定要设置
    VirtualItemCount 属性为你的数据表的纪录数
    DataGrid 才知道你有多少页
      

  12.   

    如果你要使用 DataReader 做分页
    只能是自定义分页 即:
    AllowCustomPaging =True  做自定义分页一定要设置
    VirtualItemCount 属性为你的数据表的纪录数
    DataGrid 才知道你有多少页
      

  13.   

    我想用dataset阿,不想自己作,
    但是如果把 AllowCustomPaging =True  去掉就会出错
    类型“DataGridLinkButton”的控件“Grid__ctl14__ctl1”必须放在具有 runat=server 的窗体标记内。 comm.CommandText ="Select * From bbs order by pubtime desc";
    OleDbDataAdapter adapter=new OleDbDataAdapter ();
    adapter.SelectCommand =comm;
    DataTable table = new DataTable();
    adapter.Fill(table);
    conn.Close();
    Grid.DataSource =table;
    Grid.DataBind ();<asp:DataGrid  id="Grid" AllowPaging =True  PageSize = 20 runat="server" PagerStyle-PrevPageText='上一页' PagerStyle-NextPageText='下一页'  >
    </asp:DataGrid>这样写有什么问题阿?还少什么?出现提示错误 
    类型“DataGridLinkButton”的控件“Grid__ctl24__ctl1”必须放在具有 runat=server 的窗体标记内。 
      

  14.   

    我上面说了,设成100都取了100条。。现在我改用table取了,
    但是提示 类型“DataGridLinkButton”的控件“Grid__ctl9__ctl1”必须放在具有 runat=server 的窗体标记内莫名其妙阿
      

  15.   

    没见过这样的提示,你重新拖个DataGrid进来,做个简单点的再测试一下
      

  16.   

    <form id="Form1" method="post" runat="server">
    </form>解决了,原来要放在form里面阿,大家都有分。