Answered by:
Gridview won't do paging

Question
-
User-1767698477 posted
Here's what I have: Does rowdatabound or rowcommand conflict with the paging? I have paging set to 10 and there are 11 records. When I click the link at the bottom for the next page, I don't get a page with 1 record on it. It just stays on the same page with the 10 records. How can I fix this?
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="SqlDataSource2" OnRowDataBound="Gridview2_rowdatabound" OnRowCommand="Gridview2_Rowcommand"
OnPageIndexChanging="GridView2_PageIndexChanging" CellPadding="4" ForeColor="Black"
GridLines="Vertical" Width="95%" RowStyle-HorizontalAlign="Center" PagerStyle-HorizontalAlign="NotSet"
Caption="Loan Applications" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
BorderWidth="1px" PageSize="10">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="borfirst" HeaderText="First" SortExpression="borfirst" />
<asp:BoundField DataField="borlast" HeaderText="Last" SortExpression="borlast" />
<asp:BoundField DataField="borssn" HeaderText="SSN" SortExpression="borssnt" />
<asp:BoundField DataField="appcomplete" HeaderText="App Date" SortExpression="appcomplete" />
<asp:TemplateField ShowHeader="False" HeaderText="Create File">
<ItemTemplate>
<asp:Button runat="server" Text="Create DU file" ID="CreateDUfile" CommandName="CreateDUFile"
CommandArgument='<%#Bind("borssn") %>'></asp:Button>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="3.2 File">
<ItemTemplate>
<asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="" Enabled="True"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False" HeaderText="">
<ItemTemplate>
<asp:Button ID="EditApp" Text="Edit App" runat="server" OnCommand="Secondbuttoncommand"
CommandName="Editapp" CommandArgument='<%#Bind("borssn") %>'></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>End Sub
Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'e.Row.Cells(1).Text = "<i>" & e.Row.Cells(1).Text & "</i>"
Dim Last As String = e.Row.Cells(1).Text
Dim social As String = e.Row.Cells(2).Text
Dim SSN As String = e.Row.Cells(2).Text
If Len(e.Row.Cells(2).Text) = 9 Then
SSN = SSN.Substring(5, 4)
e.Row.Cells(2).Text = "-" & SSN
End IfDim datesubmitted As String = e.Row.Cells(3).Text
If datesubmitted = "1/1/1900 12:00:00 AM" Then
e.Row.Cells(3).Text = "Unsubmitted"
e.Row.Cells(4).Enabled = False 'Create DU button is enabled by default when page loads unless changed here
Else
If datesubmitted <> "1/1/1900 12:00:00 AM" Then
'find the first whitespace character
Dim i As Int16 = InStr(datesubmitted, " ")
If i <> 0 Then
datesubmitted = datesubmitted.Substring(0, i - 1) 'truncate to just a date
e.Row.Cells(3).Text = datesubmitted
End If
End If
End If
If Left(SSN, 1) = "-" Then
SSN = SSN.Substring(1, 4) ' remove the - character
End If
Dim hl As HyperLink = CType(e.Row.FindControl("Hyperlink3"), HyperLink)
'Dim path As String = "C:/mortgageloanapply/users/" + Session("path") + "/" + Last + SSN + ".fnm" 'need to modify this line for server
Dim path As String = "h:\root\home\pacwest-001\www\MortgageLoanApply\users\" & Session("path") + "\" + Last + SSN + ".fnm" 'need to modify this line for server
hl.NavigateUrl = "./" + Session("path") + "/" + Last + SSN + ".fnm" 'need to modify this line for server
If System.IO.File.Exists(path) Then
hl.Text = "Access"
hl.Enabled = True
Else
hl.Text = "Not Created"
hl.Enabled = False
End If
End If
End Sub
Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
GridView2.PageIndex = e.NewPageIndex
GridView2.DataBind()
End Sub
Protected Sub GridView2_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
' Retrieve the row index stored in the CommandArgument property.
Dim social As Integer = Convert.ToInt32(e.CommandArgument)
CreateDUFILE(social)
End Sub<asp:gridview id="GridView2" runat="server" allowpaging="True" autogeneratecolumns="False" datasourceid="SqlDataSource2" onrowdatabound="Gridview2_rowdatabound" onrowcommand="Gridview2_Rowcommand" onpageindexchanging="GridView2_PageIndexChanging" cellpadding="4" forecolor="Black" gridlines="Vertical" width="95%" rowstyle-horizontalalign="Center" pagerstyle-horizontalalign="NotSet" caption="Loan Applications" backcolor="White" bordercolor="#DEDFDE" borderstyle="None" borderwidth="1px" pagesize="10"> <alternatingrowstyle backcolor="White"></alternatingrowstyle> <columns> <asp:boundfield datafield="borfirst" headertext="First" sortexpression="borfirst"></asp:boundfield> <asp:boundfield datafield="borlast" headertext="Last" sortexpression="borlast"></asp:boundfield> <asp:boundfield datafield="borssn" headertext="SSN" sortexpression="borssnt"></asp:boundfield> <asp:boundfield datafield="appcomplete" headertext="App Date" sortexpression="appcomplete"></asp:boundfield> <asp:templatefield showheader="False" headertext="Create File"> <itemtemplate> <asp:button runat="server" text="Create DU file" id="CreateDUfile" commandname="CreateDUFile" commandargument="<%#Bind("borssn") %>"></asp:button> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="3.2 File"> <itemtemplate> <asp:hyperlink id="HyperLink3" runat="server" navigateurl="" enabled="True"></asp:hyperlink> </itemtemplate> </asp:templatefield> <asp:templatefield showheader="False" headertext=""> <itemtemplate> <asp:button id="EditApp" text="Edit App" runat="server" oncommand="Secondbuttoncommand" commandname="Editapp" commandargument="<%#Bind("borssn") %>"></asp:button> </itemtemplate> </asp:templatefield> </columns> <footerstyle backcolor="#CCCC99"></footerstyle> <headerstyle backcolor="#6B696B" font-bold="True" forecolor="White"></headerstyle> <pagerstyle backcolor="#F7F7DE" forecolor="Black" horizontalalign="Right"></pagerstyle> <rowstyle backcolor="#F7F7DE"></rowstyle> <selectedrowstyle backcolor="#CE5D5A" font-bold="True" forecolor="White"></selectedrowstyle> <sortedascendingcellstyle backcolor="#FBFBF2"></sortedascendingcellstyle> <sortedascendingheaderstyle backcolor="#848384"></sortedascendingheaderstyle> <sorteddescendingcellstyle backcolor="#EAEAD3"></sorteddescendingcellstyle> <sorteddescendingheaderstyle backcolor="#575357"></sorteddescendingheaderstyle> </asp:gridview>
Sunday, April 12, 2020 2:08 AM
Answers
-
User-1767698477 posted
I went and copied my default.aspx file to a new default.aspx file. I also copied the code behind file piece by piece trying to find the reason it would not work. The new file works ok. So I deleted the old one and it is paging now. I downloaded and installed the screen recording program you suggested. I have 2 screens, and in addition to recording the page showing the paging, it also recorded the contents of my other screen, so I am unable to post it here.
Thanks again for you help on this.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 14, 2020 2:15 AM
All replies
-
User1535942433 posted
Hi sking,
Accroding to your description and codes, I create a demo and it works fine.As far as I think,paging and rowcommand or rowdatabound is irrelevant.
I suggest you could breakpoint and debug to check if you have entered the PageIndexChanging event.Beside,you could tell us your problems.It will help us to solve your problems.
More details,you could refer to below codes:
<div> <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False" OnRowDataBound="GridView2_RowDataBound" OnRowCommand="GridView2_RowCommand" OnPageIndexChanging="GridView2_PageIndexChanging" CellPadding="4" ForeColor="Black" GridLines="Vertical" Width="95%" RowStyle-HorizontalAlign="Center" PagerStyle-HorizontalAlign="NotSet" Caption="Loan Applications" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" PageSize="10" DataSourceID="SqlDataSource1"> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:BoundField DataField="borfirst" HeaderText="borfirst" SortExpression="borfirst" ReadOnly="True" /> <asp:BoundField DataField="borlast" HeaderText="borlast" SortExpression="borlast" /> <asp:BoundField DataField="borssn" HeaderText="borssn" SortExpression="borssn" /> <asp:BoundField DataField="appcomplete" HeaderText="appcomplete" SortExpression="appcomplete" /> <asp:TemplateField ShowHeader="False" HeaderText="Create File"> <ItemTemplate> <asp:Button runat="server" Text="Create DU file" ID="CreateDUfile" CommandName="CreateDUFile" CommandArgument='<%#Bind("borssn") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="3.2 File"> <ItemTemplate> <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="" Enabled="True"></asp:HyperLink> </ItemTemplate> </asp:TemplateField> <asp:TemplateField ShowHeader="False" HeaderText=""> <ItemTemplate> <asp:Button ID="EditApp" Text="Edit App" runat="server" OnCommand="Secondbuttoncommand" CommandName="Editapp" CommandArgument='<%#Bind("borssn") %>'></asp:Button> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#CCCC99" /> <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /> <RowStyle BackColor="#F7F7DE" /> <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#FBFBF2" /> <SortedAscendingHeaderStyle BackColor="#848384" /> <SortedDescendingCellStyle BackColor="#EAEAD3" /> <SortedDescendingHeaderStyle BackColor="#575357" /> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnet-TestApplicationWithDatabase-20190820030542 %>" SelectCommand="SELECT * FROM [Bor]"></asp:SqlDataSource> </div>
Code-behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'e.Row.Cells(1).Text = "<i>" & e.Row.Cells(1).Text & "</i>" Dim Last As String = e.Row.Cells(1).Text Dim social As String = e.Row.Cells(2).Text Dim SSN As String = e.Row.Cells(2).Text If Len(e.Row.Cells(2).Text) = 9 Then SSN = SSN.Substring(5, 4) e.Row.Cells(2).Text = "-" & SSN End If Dim datesubmitted As String = e.Row.Cells(3).Text If datesubmitted = "1/1/1900 12:00:00 AM" Then e.Row.Cells(3).Text = "Unsubmitted" e.Row.Cells(4).Enabled = False 'Create DU button is enabled by default when page loads unless changed here Else If datesubmitted <> "1/1/1900 12:00:00 AM" Then 'find the first whitespace character Dim i As Int16 = InStr(datesubmitted, " ") If i <> 0 Then datesubmitted = datesubmitted.Substring(0, i - 1) 'truncate to just a date e.Row.Cells(3).Text = datesubmitted End If End If End If If Left(SSN, 1) = "-" Then SSN = SSN.Substring(1, 4) ' remove the - character End If Dim hl As HyperLink = CType(e.Row.FindControl("Hyperlink3"), HyperLink) Session("path") = "E:\" 'Dim path As String = "C:/mortgageloanapply/users/" + Session("path") + "/" + Last + SSN + ".fnm" 'need to modify this line for server Dim path As String = "C:\Users\yijings\Desktop\image" & Session("path") + "\" + Last + SSN + ".fnm" 'need to modify this line for server hl.NavigateUrl = "./" + Session("path") + "/" + Last + SSN + ".fnm" 'need to modify this line for server If System.IO.File.Exists(path) Then hl.Text = "Access" hl.Enabled = True Else hl.Text = "Not Created" hl.Enabled = False End If End If End Sub Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) GridView2.PageIndex = e.NewPageIndex GridView2.DataBind() End Sub Protected Sub GridView2_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) ' Retrieve the row index stored in the CommandArgument property. Dim social As Integer = Convert.ToInt32(e.CommandArgument) 'CreateDUFILE(social) End Sub Protected Sub Secondbuttoncommand(sender As Object, e As CommandEventArgs) End Sub
Result:
Best regards,
Yijing Sun
Monday, April 13, 2020 2:36 AM -
User-1767698477 posted
Hi, thanks for your response and taking a look at this. I don't have a screen recorder, but when I run it, It shows a page 2 link at the bottom, but when i click the link, I'm left on the page one with the 10 records. No page 2 with 1 record. I'm using a master page. Could this have something to do with it? What program do you use for doing screen capture?
Monday, April 13, 2020 5:13 AM -
User1535942433 posted
Hi sking,
Accroding to your description,I create a demo with master page and it also work fine.I suggest you could breakpoint in the method of PageIndexChanging and debug to check if the event is executed.Check whether the gridview is rebind.
Besides,I suggest you could post your full codes to us.It will help us to solve your problems.
What program do you use for doing screen capture?I suggest you could use screentogif tool.
More details,you could refer to below article:
https://github.com/NickeManarin/ScreenToGif
Best regards,
Yijing Sun
Monday, April 13, 2020 8:59 AM -
User-1767698477 posted
I went and copied my default.aspx file to a new default.aspx file. I also copied the code behind file piece by piece trying to find the reason it would not work. The new file works ok. So I deleted the old one and it is paging now. I downloaded and installed the screen recording program you suggested. I have 2 screens, and in addition to recording the page showing the paging, it also recorded the contents of my other screen, so I am unable to post it here.
Thanks again for you help on this.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 14, 2020 2:15 AM