views:

32

answers:

3

how do i make my grdivew page more dynamic than hardcoded upto 5 pages?, below code works fine but the limitation is that i can show upto 5 pages because i have 5 linkbutons. how can i make this code more dynamic page numbers?

<asp:GridView ID="gvTable" runat="server" ShowHeader="true"      
  PageSize="5" AllowPaging="true" AllowSorting="true"      
  DataSourceID="myLinqDataSource" AutoGenerateColumns="false"      
  OnRowDataBound="GridView_DataBound">      
  <Columns>      
    <asp:BoundField DataField="Edited" HeaderText="Date" DataFormatString="{0:d}" />      
    <asp:BoundField DataField="Activity" HeaderText="Notes" />      
  </Columns>      
  <PagerTemplate>
                        <div style="float: left; margin-left: 7px; line-height: 22px;">
                            <div style="float: left;">
                                <asp:ImageButton CommandName="Page" CommandArgument="First" ToolTip="First Page"
                                    runat="server" ID="PagerFirstButton"   />
                                <asp:ImageButton ID="PagerPrevButton" CommandName="Page" CommandArgument="Prev" ToolTip="Previous Page"
                                    runat="server"  />
                            </div>
                            <div style="float: left;">
                                <div class="pagerNumber">
                                    <asp:LinkButton runat="server" ID="NumericPager1" CommandArgument="1" Text="1" CommandName="Page" />
                                </div>
                                <div class="pagerNumber">
                                    <asp:LinkButton runat="server" ID="NumericPager2" CommandArgument="2" Text="2" CommandName="Page" />
                                </div>
                                <div class="pagerNumber">
                                    <asp:LinkButton runat="server" ID="NumericPager3" CommandArgument="3" Text="3" CommandName="Page" />
                                </div>
                                <div class="pagerNumber">
                                    <asp:LinkButton runat="server" ID="NumericPager4" CommandArgument="4" Text="4" CommandName="Page" />
                                </div>
                                <div class="pagerNumber">
                                    <asp:LinkButton runat="server" ID="NumericPager5" CommandArgument="5" Text="5" CommandName="Page" />
                                </div>
                            </div>
                            <div style="float: left;">
                                <asp:ImageButton ID="PagerNextButton" CommandName="Page" CommandArgument="Next" ToolTip="Next Page"
                                    runat="server" />
                                <asp:ImageButton ID="PagerLastButton" CommandName="Page" CommandArgument="Last" ToolTip="Last Page"
                                    runat="server"  />
                            </div>
                        </div>
                        <div style="float: left; margin-left: 12px;">
                            <div style="float: left; margin: 4px 6px 0px 0px;">
                                Page Size</div>
                                                     </div>
                        <div class="gridCount" runat="server" id="divGridCount">
                            <b>1</b> Items Found &nbsp;</div>
  </PagerTemplate>  

</asp:GridView>
A: 

In your web.config file, add a parameter like GridViewPageSize. Then in your code write the following:

gvTable.PageSize= int.Parse(ConfigurationManager.AppSettings["GridViewPageSize"]);

You need to import the namespace System.Configuration for ConfigurationManager class.

Zafer
what is the purpose of it? do you understand my question? i want to make it more dynamic and you introducing new dependency :)
Abu Hamzah
It seems I did not :).
Zafer
A: 

There are two solutions for this issue

first of them is to build your pager control and override render method . the other solution is to implementing IPageableItemContainer in gridview then use DataPager control. Check the following link for last solution:

http://www.c-sharpcorner.com/uploadfile/nipuntomar/datapagergridview08012008123240pm/datapagergridview.aspx

DEVMBM
A: 

here is what i able to achive:

  <PagerStyle HorizontalAlign="Left" CssClass='header' BackColor="#E5EAF3" ForeColor="Black" />
<PagerSettings Mode="NumericFirstLast" />
Abu Hamzah