Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
        
        DataGrid1.CurrentPageIndex = e.NewPageIndex
        DataGrid1.DataBind()
    End Sub

解决方案 »

  1.   

    not exactly what you want, but take a look atServer-side ASP .NET Data Binding, Part 2: Customizing the DataGrid Control 
    http://msdn.microsoft.com/msdnmag/issues/01/04/cutting/cutting0104.asp
      

  2.   

    http://search.support.microsoft.com/search/default.aspx?Product=&KeywordType=ALL&Titles=false&numDays=&maxResults=25&withinResults=false&Queryl=datagrid&Query=datagrid&Catalog=LCID%3D2052%26CDID%3DZH-CN-SUPPORT%26PRODLISTSRC%3DOFF&QuerySource=gsfxSearch_Query
      

  3.   

    Public Class WebForm7
        Inherits System.Web.UI.Page
        Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
        Protected WithEvents dg As System.Web.UI.WebControls.DataGrid#Region " Web 窗体设计器生成的代码 "    '该调用是 Web 窗体设计器所必需的。
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()    End Sub    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
            '不要使用代码编辑器修改它。
            InitializeComponent()
        End Sub#End Region    Dim grid As System.Web.UI.WebControls.DataGrid    Dim DT As DataTable = New DataTable()
        Dim DR As DataRow    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '在此处放置初始化页的用户代码
           
            Dim i As Integer = 0
            DT.Columns.Add(New DataColumn("aaaaa"))
            For i = 0 To 9
                DR = DT.NewRow
                DR(0) = i
                DT.Rows.Add(DR)
            Next
            DataGrid1.DataSource = DT
            DataGrid1.DataBind()        setdata_dg()
        End Sub
        Sub setdata_dg()        DataGrid1.DataSource = DT
            DataGrid1.DataBind()        Dim item As DataGridItem
            For Each item In DataGrid1.Items
                grid = item.Cells(1).FindControl("dg")     '关键!!!!!            grid.DataSource = DT
                grid.DataBind()
            Next    End Sub    Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
            setdata_dg()    End Sub
    End Class
      

  4.   

    我刚刚搞定了datagrid的分页(datagrid嵌套datagrid子控件)!记得给多点分哦!!!^_^谢谢!!!
      

  5.   

    还是不行的咯,好象DATAGRID分页几麻烦的,DATAGRID自己的分页
    不行的
      

  6.   

    在html那里还要要设置!!!!
      

  7.   

    Imports System.Data
    Imports System.Data.SqlClientPublic Class ListNews
        Inherits System.Web.UI.Page
        Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid#Region " Web 窗体设计器生成的代码 "    '该调用是 Web 窗体设计器所必需的。
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()    End Sub    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
            '不要使用代码编辑器修改它。
            InitializeComponent()
        End Sub#End Region    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
        Protected WithEvents ImageButton1 As System.Web.UI.WebControls.ImageButton
        Dim Ds As DataSet = New DataSet("Myset")
        Protected WithEvents Txt_ss As System.Web.UI.WebControls.TextBox
        Protected WithEvents ddl As System.Web.UI.WebControls.DropDownList
        Dim Typename As String    Dim NewsCon As SqlConnection
        Protected WithEvents Button1 As System.Web.UI.WebControls.Button
        Dim Da As SqlDataAdapter
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '在此处放置初始化页的用户代码
            If Session("UserName") Is Nothing Or Session("UserName") = "" Then Response.Redirect("newslogin.aspx")
            Typename = Request.QueryString("typename")
           
            If Len(Typename) = 0 Then Exit Sub
            NewsCon = New SqlConnection(Application("SqlConString"))
            If Not IsPostBack Then
                ViewState("Typename") = Typename
                BindData()
            End If
        End Sub
        Sub BindData()
            Dim temp As String
            temp = "Select newsid,title,dateandtime,n_fname from newsarticle where path='" + Typename + "' and " + ddl.SelectedItem.Value + " like('%" + Txt_ss.Text + "%') order by dateandtime desc"
            Da = New SqlDataAdapter(temp, NewsCon)
            Da.Fill(Ds, Typename)
            DataGrid1.DataSource = Ds.Tables(Typename).DefaultView
            DataGrid1.DataBind()
        End Sub    Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged
            Dim Newsid As String
            Dim FileUrl As String
            Dim i As Integer
            Dim D As DateTime
            Dim temp As String        Newsid = DataGrid1.SelectedItem.Cells(0).Text
            D = CDate(DataGrid1.SelectedItem.Cells(2).Text)
            temp = D.Year.ToString + D.Month.ToString + D.Day.ToString + D.Hour.ToString + D.Minute.ToString + D.Second.ToString        FileUrl = Application("HttpPath") + "/Manage_PlatForm/News/" + ViewState("Typename") + "/" + temp + ".htm"
            Response.Redirect(FileUrl, False)
        End Sub    Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
            DataGrid1.CurrentPageIndex = e.NewPageIndex
            BindData()
        End Sub    Private Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
            On Error GoTo errh
            If ViewState("Typename") = "" Then Exit Sub
            DataGrid1.CurrentPageIndex = CInt(TextBox1.Text) - 1
            BindData()
            Exit Sub
    errh:
            If Err.Number = 5 Then
                TextBox1.Text = DataGrid1.PageCount
                DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1
                BindData()
            Else
                TextBox1.Text = 1
                DataGrid1.CurrentPageIndex = 0
                BindData()
            End If
        End Sub    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If ViewState("Typename") = "" Then Exit Sub
            DataGrid1.CurrentPageIndex = 0
            BindData()
        End Sub
    End Class<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ListNews.aspx.vb" Inherits="wjh.ListNews" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>ListNews</title>
    <meta content="Microsoft Visual Studio .NET 7.0" name="GENERATOR">
    <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body>
    <form id="Form1" method="post" runat="server">
    <P><FONT face="宋体">跳到
    <asp:textbox id="TextBox1" runat="server" Width="50px"></asp:textbox>页
    <asp:imagebutton id="ImageButton1" runat="server"></asp:imagebutton>&nbsp;&nbsp;&nbsp;
    <asp:Button id="Button1" runat="server" Text="搜索" Width="69px" Height="30px" BorderWidth="1px" ForeColor="Blue"></asp:Button>&nbsp;&nbsp;
    <asp:TextBox id="Txt_ss" runat="server"></asp:TextBox>&nbsp;
    <asp:DropDownList id="ddl" runat="server" Width="119px">
    <asp:ListItem Value="title">标题</asp:ListItem>
    <asp:ListItem Value="content">具体内容</asp:ListItem>
    </asp:DropDownList></FONT></P>
    <P><asp:datagrid id="DataGrid1" runat="server" Width="640px" GridLines="Vertical" CellPadding="3" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#999999" AutoGenerateColumns="False" AllowPaging="True" Height="207px">
    <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
    <AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
    <ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
    <HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#000084"></HeaderStyle>
    <FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
    <Columns>
    <asp:BoundColumn DataField="newsid" HeaderText="新闻ID"></asp:BoundColumn>
    <asp:ButtonColumn DataTextField="title" HeaderText="文章标题" CommandName="Select"></asp:ButtonColumn>
    <asp:BoundColumn DataField="dateandtime" HeaderText="发表日期"></asp:BoundColumn>
    </Columns>
    <PagerStyle NextPageText="下一页" PrevPageText="上一页" HorizontalAlign="Center" ForeColor="Black" Position="TopAndBottom" BackColor="#999999" Mode="NumericPages"></PagerStyle>
    </asp:datagrid></P>
    </form>
    </body>
    </HTML>