• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 629
  • Last Modified:

gridview custom paging C#

When I enable PageIndex="5" data did not show up. if I remove it; then it works. If I need to have custome no. of page to let say 5 do i have to use code behind. or how can the gridview work with custome paging. thanks!
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageIndex="5"
        AllowSorting="True" AutoGenerateColumns="False" 
        DataSourceID="EntityDataSource1">
        <Columns>
            <asp:BoundField DataField="CategoryId" HeaderText="CategoryId" 
                ReadOnly="True" SortExpression="CategoryId" />
            <asp:BoundField DataField="CatName" HeaderText="CatName" 
                ReadOnly="True" SortExpression="CatName" />
            <asp:BoundField DataField="Description" HeaderText="Description" 
                ReadOnly="True" SortExpression="Description" />
        </Columns>
    </asp:GridView>

    <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
        ConnectionString="name=eSafetyEntities" DefaultContainerName="eSafetyEntities" 
        EntitySetName="Categories" 
        Select="it.[CategoryId], it.[CatName], it.[Description]" 
         OrderBy ="it.[CategoryId]" >

Open in new window

0
fm250
Asked:
fm250
2 Solutions
 
jtdebeerCommented:
You should use PageSize = 5 and not PageIndex for PageIndex will list the 5th page of data.
(Also allow Paging = true)

If you want to have custome paging size create listbox with values 5 , 10 , 20, 50 or whatever you need.
Then in code behind on pageload event set the GridView.PageSize = Listbox.Value
0
 
himanshutCommented:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="5"
        AllowSorting="True" AutoGenerateColumns="False"
        DataSourceID="EntityDataSource1">


0
 
fm250Author Commented:
How do I add next, prev pics? thanks
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Kumaraswamy RCommented:
0
 
jtdebeerCommented:
In your GridView assign properties see the properties window under paging or simply do it programatically.
Have JPG which will act as link buttons.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1">
                    <PagerSettings FirstPageImageUrl="First.jpg" LastPageImageUrl="Last.jpg" NextPageImageUrl="Next.jpg" PreviousPageImageUrl="Previous.jpg" />
<asp:GridView>



0
 
fm250Author Commented:
I have this setings, but it did not show no of pages in the middle. I need something like:
 Prev 2 3 4 5 6 7 Next
is possible to do in the gridview or it needs programming.

<pagersettings mode="NextPreviousFirstLast" 
            firstpagetext="first" 
            lastpagetext="Last" 
            
            nextpagetext="Next" 
             
            previouspagetext="Prev"  
             
            position="Bottom"/>

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now