Reputation: 2491
I have a GridView in asp.net
page. I want to show the Page Number as Batch 1, Batch 2, Batch 3 and so on. Now when I check AllowPaging=Yes
its showing Page Number as 1, 2, 3 etc.
But I want to change this to word like Batch 1, Batch 2. Please help me with your kind suggestion.
Thanks in advance.
Upvotes: 1
Views: 2675
Reputation: 104
Harshit is right, you could write your own custom pager, but Microsoft didn't implement a variable for pre or post fixing because paging is used to display a large amount of data is sections, which means you will have numerous pages. Appending a string to every integer displayed (page#) would result in an extremely long paging footer.
The world has generally accepted paging in integer format, understanding what content of the page is. If you wish to add additional detail as to which page you're on I would suggest adding a string at the bottom of your page. This would be cleaner than having an extremely huge paging footer.
<i>Viewing Batch
<%=productsGridView.PageIndex + 1%>
of
<%=productsGridView.PageCount%>
</i>
The purpose of having the built-in gridview paging is so that we don't have to write all of our own code. Also, having 10+ pages of buttons simply doesn't make for a beautiful user interface. Seems like you have lots of options here. Good luck with your site!
Upvotes: 0
Reputation: 62311
You need to create buttons for pagination and add them to a panel or placeholder.
Here is an example -
<asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="True"
OnDataBound="GridView1_DataBound" AllowPaging="True" PageSize="2">
<PagerTemplate>
<asp:Panel ID="Panel1" runat="server" CssClass="pager" />
</PagerTemplate>
</asp:GridView>
<style type="text/css">
.pager a { padding: 3px 10px; }
</style>
protected void GridView1_DataBound(object sender, EventArgs e)
{
SetPaging();
}
private void SetPaging()
{
GridViewRow row = GridView1.BottomPagerRow;
for (int i = 1; i < GridView1.PageCount; i++)
{
var linkButton = new LinkButton
{
CommandName = "Page",
CommandArgument = i.ToString(),
Text = "Batch" + i
};
var panel = row.FindControl("Panel1") as Panel;
panel.Controls.Add(linkButton);
}
}
ASP.NET GridView with Custom Paging UI
Upvotes: 2