Quantcast
Viewing all articles
Browse latest Browse all 13

Re: Where to set GridView.PageIndex first time control is displayed

Hi Klein,

Thank you very much for your suggestion and code sample.

I can see that you are using SqlDataSource. I am using model binding with EF. I have tried the following code:

<asp:GridViewID="gridViewGuestEntries"runat="server"

ItemType="NavisWeb.Guest_Entries"

DataKeyNames="ID"

AutoGenerateColumns="false"

AllowPaging="true"

AllowSorting="false"

SelectMethod="gridViewGuestEntries_GetData"

OnPreRender="gridViewGuestEntries_PreRender"....

Code behind:

protectedvoid gridViewGuestEntries_PreRender(object sender, EventArgs e)

{

if (!IsPostBack)

{

if (gridViewGuestEntries.PageCount > 1)

gridViewGuestEntries.PageIndex = gridViewGuestEntries.PageCount - 1;

}

}

PageIndex is properly set, but in gridview first page is displayed and not the last.

Pager buttons show that the last page is selected which is not the case.


Viewing all articles
Browse latest Browse all 13

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>