How to apply paging concepts to gridview??

Posted by Vijetha under C# on 3/13/2012 | Points: 10 | Views : 3063 | Status : [Member] | Replies : 10
Hi,
I do have gridview and i need to add paging concepts to i.
How do i add it??

Regards,
Vijetha.M.M




Responses

Posted by: Sksamantaray on: 3/13/2012 [Member] Silver | Points: 25

Up
0
Down
you can go for gridview's default paging method or can go for custom paging.

 <asp:GridView ID="grdView_District" runat="server" AllowPaging="True" 

AutoGenerateColumns="False"
DataKeyNames="DistrictID" EmptyDataText="No Record Found" Font-Names="arial"
OnPageIndexChanging="ChangePage"

Width="100%" >
<Columns>
<asp:TemplateField HeaderText="DistrictID" Visible="False" >
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("DistrictID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DistrictID") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="State Name">
<ItemTemplate>
&nbsp; <asp:Label ID="Label4" runat="server" Text='<%# Bind("StateName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("StateName") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Region Name" SortExpression ="RegionID" >
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("RegionID") %>' CssClass="linkBtn"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("RegionID") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="District Name" SortExpression="DistrictName">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("DistrictName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

</Columns>

</asp:GridView>



  protected void ChangePage(object sender, GridViewPageEventArgs e)

{
grdView_District.PageIndex = e.NewPageIndex;
// Refresh the list
getViewData(null);


}


Thanks,
Sanjay

Vijetha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijetha on: 3/14/2012 [Member] Starter | Points: 25

Up
0
Down
Hi sanjay,
Its not working in my case.As i press the page number displayed on my grid,it is redirecting to my events rather than showing the next page...

Regards,
Vijetha.M.M

Vijetha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/14/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Vijetha,
Can you add your table script here.I will give you sample solution .

Thanks,
Sanjay

Vijetha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijetha on: 3/14/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Sanjay,
it is working fine now.But Im getting one more error here.
When i select any first 5 rows of my first page in grid it is doing the process fine.But when i select 2nd page first row it is giving me index out of range inorder to bind it.

Regards,
Vijetha.M.M

Vijetha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/14/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Vijetha,
Can you attach your code here?
I can modify it.

Thanks,
Sanjay

Vijetha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijetha on: 3/14/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Sanjay,
Pls find the attachment.
 Download source file

Vijetha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/14/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi vijetha,

check this



Mark this as answer, if it helps you.............
 Download source file

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Vijetha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/14/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Vijeta,
I cannot test it because,dbscript is not there and property classes also
What i see is in OnPaging
you are using BindGrid((ItemadditionItems)(Session["objdata"]));
before grd4.PageIndex = e.NewPageIndex;
Try to change its place and check.

Thanks,
Sanjay

Vijetha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 3/15/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
i wrote Simple Steps and examples on how to do paging
http://www.dotnetfunda.com/articles/article307-paging-without-a-wizard-sqldatasource-control-in-aspnet.aspx

Thank you for posting at Dotnetfunda
[Administrator]

Vijetha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response