我有一个Repeater,当数据量增加时,滚动条被显示。 当我点击转发器内的任何一行时,它会被选中并在下一个div中相应地显示数据。 假设我点击最后一条记录,数据会显示,行也会突出显示,但是滚动到达其初始位置而不是最后一个。
答案 0 :(得分:1)
protected void Page_Load(object sender, EventArgs e) { ScrolBar();}
private void ScrolBar()
{
HiddenField PosX = new HiddenField();
HiddenField PosY = new HiddenField();
HtmlControl Form1 = this.Master.FindControl("Form1") as HtmlControl;
PosX.ID = "PosX";
PosY.ID = "PosY";
Form1.Controls.Add(PosX);
Form1.Controls.Add(PosY);
string script;
script = "window.document.getElementById('" + PosX.ClientID + "').value = "
+ "window.document.getElementById('" + test1.ClientID + "').scrollLeft;"
+ "window.document.getElementById('" + PosY.ClientID + "').value = "
+ "window.document.getElementById('" + test1.ClientID + "').scrollTop;";
this.ClientScript.RegisterOnSubmitStatement(this.GetType(), "SavePanelScroll", script);
if (IsPostBack)
{
script = "window.document.getElementById('" + test1.ClientID + "').scrollLeft = "
+ "window.document.getElementById('" + PosX.ClientID + "').value;"
+ "window.document.getElementById('" + test1.ClientID + "').scrollTop = "
+ "window.document.getElementById('" + PosY.ClientID + "').value;";
this.ClientScript.RegisterStartupScript(this.GetType(), "SetPanelScroll", script, true);
}
}
答案 1 :(得分:1)
只需在Page_Load
中添加以下内容:
this.Page.MaintainScrollPositionOnPostBack = True
答案 2 :(得分:0)
您可以使用以下链接使用jquery
http://www.sergeyakopov.com/2010/11/easily-maintaining-scroll-position-in-gridview-using-jquery
答案 3 :(得分:0)
对于Repeater或GridView,请尝试以下操作: 将控制放在div中并添加一个选项OnSorting
<div id="divGridView" runat="server" >
<asp:GridView ID="Grid" runat="server" OnSorting="Grid_OnSorting"
OnDataBound="Grid_DataBound" >
代码文件上的添加此方法:
protected void Grid_OnSorting(object sender, EventArgs e)
{
divGridView.Page.SetFocus(Grid);
}