How can we do Paging in gridview? [closed]
I need to do paging in grid view that actually binds from a list. Can any one please help me out? Actually as the data is extracted from a list , am getting "null" while data it is being populated to the next page. So i would like to know whether the users here faced such a criteria.
Method used to bind the grid is as below,
private void bindGrid()
{
if (items != null)
{
foreach (var item in items)
{
name.Add(new organisationName(((System.Xml.XmlElement)((System.Xml.XmlNode[])(item))[7]).InnerText,
((System.Xml.XmlElement)((System.Xml.XmlNode[])(item))[3]).InnerText));
}
searchResultGrid.DataSource = name;
searchResultGrid.DataBind();
}
}
and in the PageIndexChanging event of gridview i used the below code
protected void searchResultGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
bindGrid();
searchResultGrid.PageIndex = e.NewPageIndex;
searchResultGrid.DataBind();
}
aspx page
<asp:GridView ID="searchResultGrid" runat="server" PageSize="20" Width="60%" AllowPaging="true"
Visible="False" OnPageIndexChanging="searchResultGrid_PageIndexChanging" OnRowDataBound="searchResultGrid_RowDataBound"
OnSelectedIndexChanged="searchResultGrid_SelectedIndexChanged" OnRowCommand="searchResultGrid_RowCommand">
<Columns>
</Columns>
<EmptyDataTemplate>
No Data Found</EmptyDataTemplate>
</asp:GridView>
Thanks in advance
Paging is a inbuilt feature of GridView control and the solution to bring them are really strait forward.
Go through this article to get better idea on paging. http://msdn.microsoft.com/en-us/library/5aw1xfh3.aspx.
You can use one of two ways to page your Gridview.
1-use the built in paging in asp.net gridview control through (AllowPaging
).
2-make your own paging way.
for more about this issue:
-GridView Examples for ASP.NET 2.0: Paging and Sorting the GridView's Data
-Grid View Paging and Sorting
-GridView Custom Paging
you can search ,and get more explanations about this feature either from articles or through a lot of videos in youtube.
精彩评论