Here is how I display the page number under the gridview:
Dim ds As New DataSet()
Dim iRecordCount As Int32
ds = (fill the dataset here)
iRecordCount = Convert.ToInt32(ds.Tables(0).Rows(0)(0))
gvMain.DataSource = ds.Tables(1)
gvMain.DataBind()
If iRecordCount Mod iPageRecords > 0 Then
iPageCount = (iRecordCount \ iPageRecords) + 1
Else
iPageCount = (iRecordCount \ iPageRecords)
End If
lblPages.Text = "of " & iPageCount.ToString()
rvPageNo.MaximumValue = iPageCount.ToString()
lblPagesDisplay.Text = ""
For i As Integer = 1 To iPageCount
If txtPageNo.Text <> i Then
Dim rawUrl As String
rawUrl = Request.RawUrl.ToString
Dim newUrl As String
newUrl = ProcessPageNumber(rawUrl, i)
lblPagesDisplay.Text += "<a href=""" & newUrl & """>" & i & "</a> "
Else
lblPagesDisplay.Text += i & " "
End If
Next
With the above code, it displays all the pages. What I want is to display only 10 pages and the rest of the pages will be represented by .... When the user clicks dots, it will move to the next 5 pages. Something like this:
Hello sujithkumar, thanks for the reply. I am not sure how this is possible because the page number that I am using now is not related with the gridview page numbering at all. If you have look, the page number is generated by these lines of code:
lblPagesDisplay.Text = ""
For i As Integer = 1 To iPageCount
If txtPageNo.Text <> i Then
Dim rawUrl As String
rawUrl = Request.RawUrl.ToString
Dim newUrl As String
newUrl = ProcessPageNumber(rawUrl, i)
lblPagesDisplay.Text += "<a href=""" & newUrl & """>" & i & "</a> "
Else
lblPagesDisplay.Text += i & " "
End If
Next
If you know the lowest number you want to show, and the highest number you want to show, you can easily do the For loop with these numbers as start and end. If the start is not the first page, add ... If the end is not the last page, add ...
Do you think that would be workable?
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
asplearning
Participant
909 Points
952 Posts
Limit pagesize of a gridview using custom paging?
Mar 22, 2012 03:50 AM|LINK
Hello everyone, I have this markup code:
<Columns> <asp:BoundField HeaderText = "ID" DataField="iParentId" /> <asp:BoundField HeaderText = "Description" DataField="sDesc" /> <asp:BoundField HeaderText = "Amount" DataField="iAmount" /> <asp:BoundField HeaderText = "Date" DataField="DateTest" /> <asp:BoundField HeaderText = "Class" DataField="classID" /> </Columns> </asp:GridView> </div> <div> <asp:linkbutton ID="PrevPage" runat="server" CommandName="PrevPage" OnCommand="Page_Changed">Prev</asp:linkbutton> <asp:label ID="lblPagesDisplay" runat="server" Text=""></asp:label> <asp:linkbutton ID="NextPage" runat="server" CommandName="NextPage" OnCommand="Page_Changed">Next</asp:linkbutton> <div> Page <asp:TextBox id = "txtPageNo" runat="server" Text="1" Width="44px"></asp:TextBox> <asp:RequiredFieldValidator ID = "rfvPageNo" runat="server" ControlToValidate="txtPageNo" ErrorMessage="*" ValidationGroup="grpGo"> </asp:RequiredFieldValidator> <asp:RangeValidator ID="rvPageNo" runat="server" ControlToValidate="txtPageNo" Type="Integer" MinimumValue="1" MaximumValue="1" ValidationGroup="grpGo"></asp:RangeValidator> <asp:Label ID="lblPages" runat="server" Text = "Dispalying Page : 1 of 1"></asp:Label> <asp:Button ID="btnGo" runat="server" Text = "Go" ValidationGroup="grpGo" onclick="btnGo_Click" /> </div> </div>Here is how I display the page number under the gridview:
Dim ds As New DataSet() Dim iRecordCount As Int32 ds = (fill the dataset here) iRecordCount = Convert.ToInt32(ds.Tables(0).Rows(0)(0)) gvMain.DataSource = ds.Tables(1) gvMain.DataBind() If iRecordCount Mod iPageRecords > 0 Then iPageCount = (iRecordCount \ iPageRecords) + 1 Else iPageCount = (iRecordCount \ iPageRecords) End If lblPages.Text = "of " & iPageCount.ToString() rvPageNo.MaximumValue = iPageCount.ToString() lblPagesDisplay.Text = "" For i As Integer = 1 To iPageCount If txtPageNo.Text <> i Then Dim rawUrl As String rawUrl = Request.RawUrl.ToString Dim newUrl As String newUrl = ProcessPageNumber(rawUrl, i) lblPagesDisplay.Text += "<a href=""" & newUrl & """>" & i & "</a> " Else lblPagesDisplay.Text += i & " " End If NextWith the above code, it displays all the pages. What I want is to display only 10 pages and the rest of the pages will be represented by .... When the user clicks dots, it will move to the next 5 pages. Something like this:
On page load:
1 2 3 4 5 6 7 8 9 10 ...
When dots are clicked, it will be:
6 7 8 9 10 11 12 13 14 15 ...
How can I achieve that?
Thanks.
sujithkumar
Contributor
3026 Points
564 Posts
Re: Limit pagesize of a gridview using custom paging?
Mar 22, 2012 04:06 AM|LINK
hi,
use can do it use grid view page index chaning event...
for ex :
protected void grvInv_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grvInv.PageIndex = e.NewPageIndex;
BingingDridMethod();// the method or function which u used to bind the grid.
}
asplearning
Participant
909 Points
952 Posts
Re: Limit pagesize of a gridview using custom paging?
Mar 22, 2012 04:17 AM|LINK
Hello sujithkumar, thanks for the reply. I am not sure how this is possible because the page number that I am using now is not related with the gridview page numbering at all. If you have look, the page number is generated by these lines of code:
lblPagesDisplay.Text = "" For i As Integer = 1 To iPageCount If txtPageNo.Text <> i Then Dim rawUrl As String rawUrl = Request.RawUrl.ToString Dim newUrl As String newUrl = ProcessPageNumber(rawUrl, i) lblPagesDisplay.Text += "<a href=""" & newUrl & """>" & i & "</a> " Else lblPagesDisplay.Text += i & " " End If NextAnd in the markup,
<asp:linkbutton ID="PrevPage" runat="server" CommandName="PrevPage" OnCommand="Page_Changed">Prev</asp:linkbutton> <asp:label ID="lblPagesDisplay" runat="server" Text=""></asp:label> <asp:linkbutton ID="NextPage" runat="server" CommandName="NextPage" OnCommand="Page_Changed">Next</asp:linkbutton> is completely in a different div from the gridview.
I tried to change For i as Integer=1 to 10. Then the page only has 10 pages. How could I tweak that around?
Thanks.
krutovdl
Member
49 Points
38 Posts
Re: Limit pagesize of a gridview using custom paging?
Mar 22, 2012 04:33 AM|LINK
I hope my solution is not too simple
but you can limit the Gridview page size on its asp by adding the follwing:
<asp:GridView ID="gvMain" runat="server" AutoGenerateColumns="false" GridLines="None" PageSize="10">
Hopefully this helps.
superguppie
All-Star
48225 Points
8679 Posts
Re: Limit pagesize of a gridview using custom paging?
Mar 22, 2012 12:50 PM|LINK
If you know the lowest number you want to show, and the highest number you want to show, you can easily do the For loop with these numbers as start and end. If the start is not the first page, add ... If the end is not the last page, add ...
Do you think that would be workable?
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.