Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Andy,</p> <p>Have you considered hooking into the gridviews OnDataBound Event and storing the appropriate gridview attributes in a cookie? You can then tap that cookie on Non PostBack PageLoad event to restore the gridview to approximately* where the user left it. </p> <ul> <li>Approximately because the gridview may be a bit different based on any CRUD operations on the source data occuring from other activity while the user was away. </li> </ul> <p>You can use the cookie expiration property if you want the page to remember its state for a long time.</p> <p>anyway...Here is some sample code. </p> <pre><code>protected void gvCountryList_DataBound(object sender, EventArgs e) { // Store gvCountryList Gridview Sort, PageIndex, and PageSize info // in a cookie so that we can redisplay same grid position next // time they visit page. HttpCookie aCookie = new HttpCookie("MaintainCountries"); aCookie["SortExp"] = gvCountryList.SortExpression.ToString(); aCookie["SortDir"] = gvCountryList.SortDirection.ToString(); aCookie["PageIndex"] = gvCountryList.PageIndex.ToString(); Response.Cookies.Add("aCookie"); ) protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { //Grab the cookies if (Request.Cookies["MaintainCountries"] != null) { if ((Request.Cookies["MaintainCountries"]["SortExp"] != null) &amp;&amp; (Request.Cookies["MaintainCountries"]["SortDir"] != null) &amp;&amp; (Request.Cookies["MaintainCountries"]["PageIndex"] != null)) { SortDirection srtDir = SortDirection.Ascending; if (Request.Cookies["MaintainCountries"]["SortDir"].ToUpper() == "DESCENDING") srtDir = SortDirection.Descending; gvCountryList.Sort(Request.Cookies["MaintainCountries"]["SortExp"].ToString(), srtDir); gvCountryList.PageIndex = Convert.ToInt32(Request.Cookies["MaintainCountries"]["PageIndex"].ToString()); } } } } </code></pre> <p>Maybe there is a better way than a cookie. </p> <p>I welcome and critique and feedback from the community. I consider myself a .net newb, so if anyone sees potential issues or danger, please offer up your thoughts.</p> <p>Mike</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload