简体   繁体   English

滚动到ASP.NET ListBox中的第一个选定项

[英]Scroll to first selected Item in ASP.NET ListBox

is there an easy way to scroll an ASP.Net ListBox automatically to the first selected Item? 有没有一种简单的方法可以自动将ASP.Net ListBox滚动到第一个选定的项目? The ListBox has SelectioMode="Multiple". 列表框具有SelectioMode =“ Multiple”。

<asp:ListBox ID="LbSymptomCodesEdit" CausesValidation="true" ValidationGroup="VG_SAVE" Height="100%" Width="100%" runat="server"  SelectionMode="Multiple"></asp:ListBox>

The ListBox is in the EditItemTemplate of a FormView inside of an UpdatePanel. 列表框位于UpdatePanel内FormView的EditItemTemplate中。 jQuery is possible but it would be great if there would be an asp.net serverside(or Ajax) way to achieve this because i don't want to use more client scripts than really needed(and this is only a nice to have). jQuery是可能的,但是如果有一个asp.net服务器端(或Ajax)方法来实现这一点,那就太好了,因为我不想使用比实际需要更多的客户端脚本(这真是太好了)。

I don't believe there is any server side method to achieve what you want to. 我不相信有任何服务器端方法可以实现您想要的。 For example, the ASP.Net Page option "MaintainScrollPositionOnPostback" and the validator's "SetFocusOnError" properties all inject a small amount of javascript into a page to manage this. 例如,ASP.Net页面选项“ MaintainScrollPositionOnPostback”和验证器的“ SetFocusOnError”属性都将少量的javascript注入到页面中进行管理。

If you really want to be able to scroll to the first selected item, I suggest you inherit from ListBox and add code that will inject javascript (or jQuery) to control this for you. 如果您真的希望能够滚动到第一个选定的项目,建议您从ListBox继承并添加代码,该代码将注入javascript(或jQuery)来为您控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM