how to add paging option to my datagrid
Hi experts. I want to add paging option to my datagrid.(5 records per page) I be happy if some one help me put
pagaing option to my datagrid .Thanks
Code:
<form runat="server">
<asp:DataGrid id="DBEditDataGrid" runat="server"
BorderWidth = "1" CellSpacing = "2" CellPadding = "2"
HeaderStyle-Font-Bold = "True"
OnEditCommand = "DBEditDataGrid_Edit"
OnCancelCommand = "DBEditDataGrid_Cancel"
OnUpdateCommand = "DBEditDataGrid_Update"
AutoGenerateColumns = "False"
>
<Columns>
<asp:BoundColumn HeaderText="PLAYERNO" DataField="PLAYERNO" ReadOnly="True" />
<asp:BoundColumn HeaderText="NAME" DataField="NAME" />
<asp:BoundColumn HeaderText="INITIALS" DataField="INITIALS" />
<asp:BoundColumn HeaderText="BIRTH_DATE" DataField="BIRTH_DATE" />
<asp:BoundColumn HeaderText="SEX" DataField="SEX" />
<asp:BoundColumn HeaderText="JOINED" DataField="JOINED" />
<asp:BoundColumn HeaderText="STREET" DataField="STREET" />
<asp:BoundColumn HeaderText="HOUSENO" DataField="HOUSENO" />
<asp:BoundColumn HeaderText="POSTCODE" DataField="POSTCODE" />
<asp:BoundColumn HeaderText="TOWN" DataField="TOWN" />
<asp:BoundColumn HeaderText="PHONENO" DataField="PHONENO" />
<asp:BoundColumn HeaderText="LEAGUENO" DataField="LEAGUENO" />
<asp:EditCommandColumn
HeaderText = "Edit"
EditText = "Edit"
CancelText = "Cancel"
UpdateText = "Update"
/>
<asp:HyperLinkColumn
HeaderText="Penalty"
DataNavigateUrlField="playerno"
DataNavigateUrlFormatString="./penaltyupdate.aspx?person_id={0}"
DataTextField="playerno"
DataTextFormatString="{0:c}"
Target="_blank"/>
<asp:HyperLinkColumn
HeaderText="TEAMS"
DataNavigateUrlField="playerno"
DataNavigateUrlFormatString="./teamsupdate.aspx?person_id={0}"
DataTextField="playerno"
DataTextFormatString="{0:c}"
Target="_blank"/>
<asp:HyperLinkColumn
HeaderText="MATCHES"
DataNavigateUrlField="playerno"
DataNavigateUrlFormatString="./matchesupdate.aspx?person_id={0}"
DataTextField="playerno"
DataTextFormatString="{0:c}"
Target="_blank"/>
<asp:HyperLinkColumn
HeaderText="COMMITTEE_MEMBERS"
DataNavigateUrlField="playerno"
DataNavigateUrlFormatString="./committeeupdate.aspx?person_id={0}"
DataTextField="playerno"
DataTextFormatString="{0:c}"
Target="_blank"/>
</Columns>
</asp:DataGrid>
</form>
Re: how to add paging option to my datagrid
To use the paging built into the DataGrid just set AllowPaging property to true and the PageSize property to how many items you want on the page. You can also set the PagerStyle to change the way the pager looks.
BTW this method of paging isn't that efficient you might want to look into custom paging.
HTH
DJ
Re: how to add paging option to my datagrid
Re: how to add paging option to my datagrid
To add numeric paging to your grid use:
Code:
<asp:DataGrid id="DataGrid1" runat="server" PageSize="5" AllowPaging="True">
<PagerStyle Mode="NumericPages">
</PagerStyle>
</asp:DataGrid>
For next and previous buttons use:
Code:
<asp:DataGrid id="DataGrid1" runat="server" PageSize="5" AllowPaging="True">
</asp:DataGrid>
Then you need to add the following code to handle the page change:
VB Code:
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
'bind data source to grid
End Sub
Hope that helps.
Woka
Re: how to add paging option to my datagrid
I'm still having problems throwing exeptions after changing pages. Some times it works greate, others blow a gasket. I'll try your code, thanks for the response.