如何用代码实现在ListBox(web)中让垂直滚动条滚动到指定位置

时间:2022-04-01 13:10:18
现要在ASP.NET中实现这样一个小功能:

    一个列表框中的项很多(有200项),一次只能显示20项,我想在后台代码中实现在指定选定项(如指定索引为100的项被选中,而当前选定项是第一项)的同时,让滚动条滚动到选定项位置,以便让用户能直接看到选定项是什么,而不用手工拖动

3 个解决方案

#1


可以通过下面的方法实现,每个ListBox中需要定义<a name = "#q1"></a>,它就是起到一个定位的作用。

<html>
<table>
  <tr>
    <td height="400"><a href="Link_to_certain_place.htm#q1">link1</a>
    </td>    
  </tr>
  <tr>
    <td height="400"><a href="Link_to_certain_place.htm#q2">link2</a>
    </td>    
  </tr>
</table>
<table>
  <tr>
    <td height="400"><a name = "#q1"></a>link1 link1 link1 link1 link1 link1
    </td>    
  </tr>
  <tr>
    <td height="400"><a name = "#q2"></a>link2 link2 link2 link2 link2 link2
    </td>    
  </tr>
</table>
</html>

#2


你好,我要实现的ListBox中的项是动态添加的(就是根据一个项类型的下拉列表集合中选中的类型动态的绑定这个ListBox中的项),在后台中遍历当前ListBox中包含的项集合,选中满足特定条件的项,并让滚动条滚动到选中项位置

#3


ListBox1.Items[1].Selected

#1


可以通过下面的方法实现,每个ListBox中需要定义<a name = "#q1"></a>,它就是起到一个定位的作用。

<html>
<table>
  <tr>
    <td height="400"><a href="Link_to_certain_place.htm#q1">link1</a>
    </td>    
  </tr>
  <tr>
    <td height="400"><a href="Link_to_certain_place.htm#q2">link2</a>
    </td>    
  </tr>
</table>
<table>
  <tr>
    <td height="400"><a name = "#q1"></a>link1 link1 link1 link1 link1 link1
    </td>    
  </tr>
  <tr>
    <td height="400"><a name = "#q2"></a>link2 link2 link2 link2 link2 link2
    </td>    
  </tr>
</table>
</html>

#2


你好,我要实现的ListBox中的项是动态添加的(就是根据一个项类型的下拉列表集合中选中的类型动态的绑定这个ListBox中的项),在后台中遍历当前ListBox中包含的项集合,选中满足特定条件的项,并让滚动条滚动到选中项位置

#3


ListBox1.Items[1].Selected