我有一个中继器,当数据数量增加时,会显示滚动条。当我单击中继器内的任何行时,它会被选中,并在下一个 div 中相应地显示数据。假设我单击最后一条记录,显示数据并且行也突出显示,但滚动到它的初始位置而不是最后一个。
问问题
6258 次
4 回答
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);
}
}
于 2013-09-14T11:47:45.737 回答
1
只需将以下内容放入Page_Load
:
this.Page.MaintainScrollPositionOnPostBack = True
于 2014-03-14T16:50:53.343 回答
1
对于 Repeater 或 GridView 试试这个:Put control inside div and add an option 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);
}
于 2013-09-20T18:26:49.390 回答
0
您可以使用以下链接使用 jquery
http://www.sergeyakopov.com/2010/11/easy-maintaining-scroll-position-in-gridview-using-jquery
于 2013-09-14T06:12:49.497 回答