2010-06-03 95 views
0

我已經綁定了數據集控件到列表視圖。我如何滾動到錨點?

我想滾動到DataPager點擊列表視圖控件的第一項。我認爲這應該用JavaScript來完成。這似乎是數據手冊不允許的。

我有什麼選擇?如何在單擊DataPager時滾動到特定的錨點?

回答

0

感謝添!

對於那些懶惰的人(就像我一樣),這裏是VB.NET的等價物。 它包含錯字更正和新的RegisterClientScriptBlock Method

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
     FocusControlOnPageLoad("Label1", Me.Page) 
End Sub 

Public Sub FocusControlOnPageLoad(ByVal ClientID As String, ByVal page As System.Web.UI.Page) 
     Dim csName As String = "ScrollViewScript" 
     Dim csType As Type = Me.GetType 
     Dim cs As ClientScriptManager = page.ClientScript 
     If Not cs.IsClientScriptBlockRegistered(csType, csName) Then 
      Dim csText As New StringBuilder() 
      csText.Append("<script>function ScrollView(){") 
      csText.Append("var el = document.getElementById('" & ClientID & "');") 
      csText.Append("if (el != null){") 
      csText.Append("el.scrollIntoView();") 
      csText.Append("el.focus();}}") 
      csText.Append("window.onload = ScrollView;") 
      csText.Append("</script>") 
      cs.RegisterClientScriptBlock(csType, csName, csText.ToString()) 
     End If 
    End Sub