Visual Studio 2005 makes very easy the whole listing of data with paging links at the bottom. If we use a SQLDataSource object on the ASP page, all the paging and sorting is handled automatically, and can even have an AJAX kind of functionality if we turn on "EnablePagingAndSortingCallbacks". the grid pages and sorts without what some people consider to be a nasty page flash.
In a meeting about 2 months ago, some ultra-powerful managers shreaked in fear of the little numbered paging links at the bottom of the page. They demanded the pages be switched to scrolling wherever possible. So I promptly wrapped my GridView controls in DIV tags with style "overflow-y:scroll". This accomplished some immediate relief but not without some hangover.
If the user does some interacting with your list items, and a PostBack occurs, your page will refresh with the scroll position back to the top and the item down in the list the user was playing with, will be invisible. Thanks to Scott Guthrie for reminding us of the "ScrollIntoView" javascript function.
That article
One thing I would warn about is that controls get named AGAIN with unique names by the ASPX page when they are rendered, so you have to get that unique name down to the client javascript for it to be able to find the GridView row you want "scrolled into view". The control on the client side will end up with an ID such as
"ctl00_ContentPlaceHolder1_GridViewMyListOfItems_ctl51_ctl00"
What a mess.
here is a partial code sample to attempt to scroll this thing :
// Assuming you wanted the 112th row and
// had an index variable to use here,
// not a hardcoded one
Control control =
myGrid.Rows[112].Cells[1].Controls[1] as Control;
string scriptText =
"< script >
document.getElementById('" +
control.ClientID +
"').scrollIntoView(); < /script >";
Doing all this in the PreRender phase of the page lifecycle, you can get the script into action with a call to "ClientScript.RegisterStartupScript" or some other variant in the array of new client scripty things in .Net.
Now if we could just get my management to agree on a standard for this, my days would be half as long ;-)
No comments:
Post a Comment