现要在ASP.NET中实现这样一个小功能:    一个列表框中的项很多(有200项),一次只能显示20项,我想在后台代码中实现在指定选定项(如指定索引为100的项被选中,而当前选定项是第一项)的同时,让滚动条滚动到选定项位置,以便让用户能直接看到选定项是什么,而不用手工拖动    简单说就是如何能在后台控制一个ListBox控件中的垂直滚动条滚动到指定的选择项位置

解决方案 »

  1.   

    不好意思,楼主,我试了下,找到了解决方案了:
        <form id="form1" runat="server">
        <div>
                    <select id="Select1" name="Select1" size="4" style="width: 81px">
                <option>a</option>
                <option>ab</option>
                <option>ac</option>
                <option>ad</option>
                <option>ae</option>
                <option>af</option>
                <option>ag</option>
                <option>ah</option>
                <option>ai</option>
                <option>aj</option>
                <option>ak</option>
            </select>
        </div>
        </form>
        <script type="text/javascript">
        document.getElementById("Select1").selectedIndex = 4;
        </script>
      

  2.   

    <form id="form1" runat="server">
        <div>
            <cc1:webcustomcontrol1 id="WebCustomControl1_1" runat="server"></cc1:webcustomcontrol1>
            <br />
            <br />
            <asp:ListBox ID="ListBox1" runat="server" Width="53px">
                <asp:ListItem>a</asp:ListItem>
                <asp:ListItem>b</asp:ListItem>
                <asp:ListItem>d</asp:ListItem>
                <asp:ListItem>c</asp:ListItem>
                <asp:ListItem>e</asp:ListItem>
                <asp:ListItem>f</asp:ListItem>
                <asp:ListItem>g</asp:ListItem>
                <asp:ListItem>h</asp:ListItem>
            </asp:ListBox><br />
            <br />
            <select id="Select1" name="Select1" size="4" style="width: 81px">
                <option>a</option>
                <option>ab</option>
                <option>ac</option>
                <option>ad</option>
                <option>ae</option>
                <option>af</option>
                <option>ag</option>
                <option>ah</option>
                <option>ai</option>
                <option>aj</option>
                <option>ak</option>
            </select>
        </div>
        </form>
        <script type="text/javascript">
        document.getElementById("Select1").selectedIndex = 4;
        document.getElementById("ListBox1").selectedIndex = 4;
        </script>
      

  3.   

    你好,我要实现的ListBox中的项是动态添加的(在后台访问数据库得到需要的数据再绑定ListBox),在后台中遍历当前ListBox中包含的项集合,选中满足特定条件的项,并让滚动条滚动到选中项位置.注意我要实现的关键-是在后台代码中控制垂直滚动条的滚动,我用的ListBox是Web服务器控件,非HTML控件现在的情况是这样的,这个ListBox可能会在运行时被动态添加很多项(如200项,而当前不拖动滚动条只能显示20项),我也试过了,当滚动条在第一项位置时,我改变选定项(非直接手动选定.而是在后台程序中自动触发)到第100项时,必须手工拖动滚动条才能看到此项,我要实现的就是在后台滚动条的滚动到指定选定项位置