如何用代码实现在ListBox(web)中让垂直滚动条滚动到指定位置 现要在ASP.NET中实现这样一个小功能: 一个列表框中的项很多(有200项),一次只能显示20项,我想在后台代码中实现在指定选定项(如指定索引为100的项被选中,而当前选定项是第一项)的同时,让滚动条滚动到选定项位置,以便让用户能直接看到选定项是什么,而不用手工拖动 简单说就是如何能在后台控制一个ListBox控件中的垂直滚动条滚动到指定的选择项位置 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不好意思,楼主,我试了下,找到了解决方案了: <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> <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> 你好,我要实现的ListBox中的项是动态添加的(在后台访问数据库得到需要的数据再绑定ListBox),在后台中遍历当前ListBox中包含的项集合,选中满足特定条件的项,并让滚动条滚动到选中项位置.注意我要实现的关键-是在后台代码中控制垂直滚动条的滚动,我用的ListBox是Web服务器控件,非HTML控件现在的情况是这样的,这个ListBox可能会在运行时被动态添加很多项(如200项,而当前不拖动滚动条只能显示20项),我也试过了,当滚动条在第一项位置时,我改变选定项(非直接手动选定.而是在后台程序中自动触发)到第100项时,必须手工拖动滚动条才能看到此项,我要实现的就是在后台滚动条的滚动到指定选定项位置 asp.net 能不能实现局域网发邮件 需要安装.net framework 1.1,在安装过程中出现【错误1933】,怎么办? 换了服务器后,打开网站除首页的其他页面都会回到首页怎么解决? 大型网站的上传图片,文件处理? Tabstrip的问题 求單點登錄與退出代碼 未将对象引用设置到对象的实例 ASP 页面跳转时传递参数应该怎么写 *****可以在自己写的windows服务里面加上方法或是属吗? 类方法的返回类型可以是任意类型的吗? 等待~$&^(*_(+)*^$$!!!!!从一段HTML代码中提取图片 ASP.NET如何进行配置?晕!晕!!晕!!!
<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>
<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>