1

I have a GridView control that uses a datatable for a data source. I have enabled paging on the control, and the GridView shows the number of rows I've specified as the PageSize. However, there is no paging navigation, so I have no way to change the page.

Question: How do I get the paging navigation to show?

GridView definition:

<asp:GridView runat="server" ID="gvResults" CssClass="report" DataKeyNames="LogId" AllowSorting="True" AllowPaging="True" PageSize="5" OnRowDataBound="gvResults_OnRowDataBound" OnPageIndexChanging="gvResults_OnPageIndexChanging"></asp:GridView> 

C#:

//...stuff that gets data from database DataTable dt = oDs.DataSet.Tables[0]; gvResults.DataSource = dt; gvResults.DataBind(); 

NOTE: I've verified in debugger that the datatable dt has more than 100 rows

And the OnPageIndexChanging() event, based on the answer to this question, although it didn't work in my case (I'm not sure why it's necessary since the event shouldn't trigger until you attempt to go to the next page, which would require the paging navigation to show in the first place, right?):

protected void gvResults_OnPageIndexChanging(object sender, GridViewPageEventArgs e) { GridView gv = (GridView)sender; DataView dv = gv.DataSource as DataView; if (dv != null) { DataTable dt = dv.Table; gv.DataSource = dt; } gv.PageIndex = e.NewPageIndex; gv.DataBind(); } 

Here is what I see: results

I expect to see some way to page through the results.

I have also tried adding a PagerSettings to my GridView, like so:

<asp:GridView runat="server" ID="gvResults" CssClass="report" DataKeyNames="LogId" AllowSorting="True" AllowPaging="True" PageSize="5" OnRowDataBound="gvResults_OnRowDataBound" OnPageIndexChanging="gvResults_OnPageIndexChanging"> <PagerSettings Mode="NextPreviousFirstLast" FirstPageText="First" LastPageText="Last" NextPageText="Next" PreviousPageText="Previous" Position="Bottom"></PagerSettings> </asp:GridView> 

Here is what the rendered HTML looks like for that last row. I modified the css during runtime to expand the row so it's clear that the row is empty. There are no paging controls being hidden by css.

html rendering

2
  • 1
    check the html rendered code, maybe some css is hiding it Commented Jun 18, 2016 at 0:06
  • @Aristos - I have updated my question with a screenshot of the rendered HTML. There is nothing in the row that should have the paging controls. Commented Jun 20, 2016 at 16:10

1 Answer 1

2

After much banging of head and gnashing of teeth, I finally figured this out.

I have another event that operates OnRowDataBound() which formats a particular column to HTML, and this conversion resulted in no paging controls when it operated on the footer row.

The solution was to check that the bound row is a DataRow before doing the conversion.

protected void gvResults_OnRowDataBound(object sender, GridViewRowEventArgs e) { if (!(sender is GridView) || e.Row.RowType != DataControlRowType.DataRow) return; //do stuff } 

And then happiness ensued:

happiness

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.