I have a GridView where I have to show top 200 records on page load and I have set the pagesize="200" in the design. But when I give this property Paging doesn't show in the GridView and when I remove the pagesize="200" property the paging shows up.
The actual case is when I remove the pagesize="200" I am only able to see only 10 records instead of 200 even though my DataTable returns 200 records.
I have also enabled AllowPaging="true".
Can anyone please suggest an alternate or any inputs? It is much appreciated.
HTML Code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true" ShowHeaderWhenEmpty="true" EmptyDataText="No Records Found" OnRowDataBound="GridView1_RowDataBound" AllowSorting="true" OnSorting="GridView1_Sorting" OnPageIndexChanging="GridView1_PageIndexChanging" AllowPaging="true" CellPadding="1" PageSize="200" CellSpacing="1" BackColor="#e7e7e8" BorderColor="#e7e7e8" GridLines="Both" CssClass="GridViewStyleB" Font-Names="Calibri" Font-Size="10pt"> <PagerSettings Mode="NumericFirstLast" PageButtonCount="4" FirstPageText="First" LastPageText="Last" Position="Top" Visible="true" /> <PagerStyle BackColor="#e7e7e8" ForeColor="Black" HorizontalAlign="left" /> <HeaderStyle CssClass="RowStyle" ForeColor="Black" BackColor="#a9a9a9" Font-Underline="false" HorizontalAlign="Left" /> <RowStyle CssClass="RowStyle" HorizontalAlign="Left" BorderColor="#E7E7E8" ForeColor="Black" /> <AlternatingRowStyle CssClass="AlternatingRowStyle" BorderColor="#E7E7E8" ForeColor="Black" BackColor="#e7e7e8" /> <EmptyDataRowStyle HorizontalAlign="Center" /> </asp:GridView> Code Behind:
protected void GridView1_PreRender(object sender, EventArgs e) { GridView gv = (GridView)sender; GridViewRow pagerRow = (GridViewRow)gv.TopPagerRow; GridView1.VirtualItemCount = totalRecords; if (pagerRow != null && pagerRow.Visible == false) pagerRow.Visible = true; } Update1:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { GridView1.TopPagerRow.Visible = true; int totalRecords = DAL.GetRecordCount(); GridView1.VirtualItemCount = totalRecords; } }
AutoPostBack="true"attribute to your gridview.AutoPostBack="true"and still paging isn't visible.