编程滚动/移动到在.NET ASP项目:ListView控件 [英] Programmatically scroll/move to an item in a .net asp:listview control

查看:116
本文介绍了编程滚动/移动到在.NET ASP项目:ListView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,有一个asp:ListView和我试图找出如何以编程方式滚动到某个项目。这里是我的ASPX标记:

I have a web page that has an asp:ListView and I am trying to figure out how to programmatically scroll to a certain item. Here is my aspx markup:

<asp:ListView ID="lvGlossary" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="lvGlossary_ItemDataBound">
    <LayoutTemplate>
        <div class="glossaryTitle">Glossary</div>
        <div id="ItemPlaceholder" runat="server"></div>
        <br />
    </LayoutTemplate>
    <ItemTemplate>
        <div class="glossaryEntry">
            <span class="glossaryWord">
                <asp:Label ID="lbWord" runat="server" Text='<%# Bind("Word") %>' />: 
            </span>
            <span class="glossaryDefinition">
                <asp:Label ID="lbDefinition" runat="server" Text='<%# Bind("Definition") %>' />
            </span>
            <br />
        </div>
    </ItemTemplate>
    <AlternatingItemTemplate>
        <div class="glossaryEntryAlternating">
            <span class="glossaryWord">
                <asp:Label ID="lbWord" runat="server" Text='<%# Bind("Word") %>' />: 
            </span>
            <span class="glossaryDefinition">
                <asp:Label ID="lbDefinition" runat="server" Text='<%# Bind("Definition") %>' />
            </span>
            <br />
        </div>
    </AlternatingItemTemplate>
</asp:ListView>

在我的C#code后面我用填充文字和当用户选择一个字,我想自动滚动到这个词在ListView所以它是可见的文本框。它最有可能需要做客户端,所以我想我需要一些JavaScript来做到这一点。任何人都可以点我如何做到这一点的例子吗?

In my c# code behind I am populating a text box with text and when the user selects a word I want to automatically scroll to the word in the listview so it is visible. It most likely needs to be done client side, so I think I need some javascript to do this. Can anyone point me to an example of how to do this?

任何帮助是AP preciated !!

Any help is appreciated!!

感谢您

推荐答案

您可以使用一个元素的scrollIntoView JavaScript方法:

You could use an element's scrollIntoView javascript method:

document.getElementById('id').scrollIntoView(true);

这篇关于编程滚动/移动到在.NET ASP项目:ListView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆