Maintain Scroll Position of Gridview
1.) Add two hidden textboxes namely hidDiv1 and hidDiv2
input id="hidDiv1" type="hidden" name="hidden1" runat="server"
input id="hidDiv2" type="hidden" name="hidden2" runat="server"
2.) Add this code in the aspx page under script tag
script type="text/javascript" language="javascript"
function saveScrollPos1()
{
document.getElementById('hidDiv1').value = document.getElementById('div1').scrollTop;
}
function SetScrollPos1()
{
document.getElementById('div1').scrollTop = document.getElementById('hidDiv1').value;
}
function saveScrollPos2()
{
document.getElementById('hidDiv2').value = document.getElementById('div2').scrollTop;
}
function SetScrollPos2()
{
document.getElementById('div2').scrollTop = document.getElementById('hidDiv2').value;
}
/script
3.) under the onload event of body tag
body onload="SetScrollPos1();SetScrollPos2()"
4.) and on the onscroll event of div1 tag add
onscroll="saveScrollPos1()"
and the onscroll event of div2 tag add
onscroll="saveScrollPos2()"
Explanation:
Save the scroll position of div1 to the hidden textbox hiddiv1 and
then set the scroll value of hiddiv1 to the div1 on the onload event of body tag
input id="hidDiv1" type="hidden" name="hidden1" runat="server"
input id="hidDiv2" type="hidden" name="hidden2" runat="server"
2.) Add this code in the aspx page under script tag
script type="text/javascript" language="javascript"
function saveScrollPos1()
{
document.getElementById('hidDiv1').value = document.getElementById('div1').scrollTop;
}
function SetScrollPos1()
{
document.getElementById('div1').scrollTop = document.getElementById('hidDiv1').value;
}
function saveScrollPos2()
{
document.getElementById('hidDiv2').value = document.getElementById('div2').scrollTop;
}
function SetScrollPos2()
{
document.getElementById('div2').scrollTop = document.getElementById('hidDiv2').value;
}
/script
3.) under the onload event of body tag
body onload="SetScrollPos1();SetScrollPos2()"
4.) and on the onscroll event of div1 tag add
onscroll="saveScrollPos1()"
and the onscroll event of div2 tag add
onscroll="saveScrollPos2()"
Explanation:
Save the scroll position of div1 to the hidden textbox hiddiv1 and
then set the scroll value of hiddiv1 to the div1 on the onload event of body tag
Comments
Post a Comment