Results 1 to 5 of 5

Thread: how to add paging option to my datagrid

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Talking 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>

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    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

    If I have been helpful please rate my post. If I haven't tell me!

  3. #3
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: how to add paging option to my datagrid

    Last edited by wild_bill; Jul 29th, 2005 at 05:45 PM.

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    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:
    1. Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
    2.     DataGrid1.CurrentPageIndex = e.NewPageIndex
    3.     'bind data source to grid
    4. End Sub
    Hope that helps.

    Woka

  5. #5
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width