62,025
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TreeView1.Nodes.Clear();
for (int i = 0; i < 50; i++)
{
TreeNode node = new TreeNode();
node.Text = "树节点" + i;
TreeView1.Nodes.Add(node);
}
}
dd();
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
TextBox1.Text = TreeView1.SelectedNode.Value;
}
public void dd()
{
HiddenField oScrollPosX = new HiddenField();
oScrollPosX.ID = "ScrollPosX";
Form.Controls.Add(oScrollPosX);
HiddenField oScrollPosY = new HiddenField();
oScrollPosY.ID = "ScrollPosY";
Form.Controls.Add(oScrollPosY);
string s =
"window.document.getElemntById('{0}').value=window.document.getElemntById('left').scrollLeft;window.document.getElemntById('{1}').value=window.document.getElemntById('left').scrollTop;";
s = string.Format(s, oScrollPosX.ClientID, oScrollPosY.ClientID);
Page.ClientScript.RegisterOnSubmitStatement(Page.GetType(), "SavePanelScroll", s);
if (IsPostBack)
{
oScrollPosX.Value = Request.Form[oScrollPosX.ClientID];
oScrollPosY.Value = Request.Form[oScrollPosY.ClientID];
string ss = "window.document.getElementById('{0}').scrollLeft = {1};window.document.getElementById('{0}').scrollTop = {2};";
ss = string.Format(ss, left.ClientID, oScrollPosX.Value, oScrollPosY.Value);
Page.ClientScript.RegisterStartupScript(Page.GetType(), "SetPanelScroll", ss, true);
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"
MaintainScrollPositionOnPostback="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div id="left" runat="server" style="float: left; text-align: left; width: 220px;
height: 440px; overflow: scroll; border: #003278 1px solid">
<asp:TreeView ID="TreeView1" runat="server" ShowExpandCollapse="False" BorderStyle="None"
OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" NodeIndent="10">
<SelectedNodeStyle Font-Bold="True" Font-Underline="True" />
</asp:TreeView>
</div>
<div id="d">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
</form>
</body>
</html>
sScript = "window.document.getElementById('" & Panel1.ClientID & "').scrollLeft = " & oScrollPosX.Value & ";" & _
"window.document.getElementById('" & Panel1.ClientID & "').scrollTop = " & oScrollPosY.Value & ";"
sScript = "window.document.getElementById('{0}').scrollLeft = {1};window.document.getElementById('{0}').scrollTop = {2};";
sScript =string.Format(sScript,Panel1.ClientID,oScrollPosX.Value,oScrollPosY.Value);
oScrollPosX.Value = Me.Request.Form(oScrollPosX.ClientID)
oScrollPosY.Value = Me.Request.Form(oScrollPosY.ClientID)
oScrollPosX.Value = Request.Form[oScrollPosX.UniqueID];
oScrollPosY.Value = Request.Form[oScrollPosY.UniqueID];
function bindData(){
document.getElementById("divScrollValue").value = document.getElementById("left").scrollTop;
}
function ScrollToSelectNode()
{
document.getElementById("left").scrollTop = "<%=ScrollValue%>";
}