<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" SmartNavigation="true" %> |
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" MaintainScrollPositionOnPostback="true" %> |
<input type="hidden" name="TreeView1_SelectedNode" id="TreeView1_SelectedNode" value="TreeView1t54" /> |
为了具体说明做法,我使用TreeView编写了一些代码,在Page_Load时间里加载一段脚本来找到需要的单元格(参考下表),在<body>的onload时间里调用该函数.
Imports System.Collections.Generic Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Load InjectLoadEvent() If (IsPostBack) Then Return TreeView1.Nodes.Clear() Dim chicken As New TreeNode("Chicken") TreeView1.Nodes.Add(chicken) Dim beef As New TreeNode("Beef") TreeView1.Nodes.Add(beef) Dim pork As New TreeNode("Pork") TreeView1.Nodes.Add(pork) Dim fish As New TreeNode("Fish") TreeView1.Nodes.Add(fish) chicken.ChildNodes.Add(New TreeNode("Crepes Florentine with Buffalo Chicken")) fish.ChildNodes.Add(New TreeNode("Linguine with White Clam Sauce")) pork.ChildNodes.Add(New TreeNode("Pork Loin with Peanut and Madarin Orange Sauce")) beef.ChildNodes.Add(New TreeNode("Standing Rib Roast with Fennel and Blue Cheese Potatoes")) ' We need a bunch of stuff here so we will add some stubs Dim I As Integer For I = 1 To 50 chicken.ChildNodes.Add(New TreeNode("Placeholder " + I.ToString())) fish.ChildNodes.Add(New TreeNode("Placeholder " + I.ToString())) pork.ChildNodes.Add(New TreeNode("Placeholder " + I.ToString())) beef.ChildNodes.Add(New TreeNode("Placeholder " + I.ToString())) Next TreeView1.CollapseAll() End Sub Public Sub InjectLoadEvent() Dim script As String = _ "function LoadEvent()" + _ "{{" + _ " try" + _ " {{" + _ " var elem = document.getElementById('{0}_SelectedNode');" + _ " if(elem != null )" + _ " {{" + _ " var node = document.getElementById(elem.value);" + _ " if(node != null)" + _ " {{" + _ " node.scrollIntoView(true);" + _ " {1}.scrollLeft = 0;" + _ " }}" + _ " }}" + _ " }}" + _ " catch(oException)" + _ " {{}}" + _ "}}" Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "LoadEvent", _ String.Format(script, TreeView1.ClientID, Panel1.ClientID), True) End Sub End Class |