开发者

How can we do Paging in gridview? [closed]

开发者 https://www.devze.com 2023-03-11 18:16 出处:网络
开发者_开发技巧 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
开发者_开发技巧 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号