Tuesday, April 17, 2007

Datagrid Paging


<asp:datagrid id="DataGrid1" runat="server" AllowPaging="True"
PageSize="5"></asp:datagrid>

    Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'Fill the Dataset
Dim ds As New DataSet()
ds.ReadXml(Server.MapPath(".") & "\..\Xml\PartList.xml")

'Set the DataGrid's Source and bind it.
DataGrid1.DataSource = ds
If Not IsPostBack Then
DataGrid1.DataBind()
End If

'Dispose Items
ds.Dispose()
End Sub

'Implement the EventHandler for PageIndexChanged
Private Sub ChangePage(ByVal source As Object, ByVal e As _
System.Web.UI.WebControls.DataGridPageChangedEventArgs) _
Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataBind()
End Sub