怎样将listbox中被选中的项对齐到listbox框的首行呢?

解决方案 »

  1.   

    在ListBox的SelectedIndexChanged事件中:
    if (this.ListBox1.SelectedIndex > 0)
    {
    ListItem se = this.ListBox1.SelectedItem;
    this.ListBox1.Items.Remove(se);
    this.ListBox1.Items.Insert(0,se);
    }
    你需要把ListBox的AutoPostBack属性设为true.
      

  2.   

    如果用.NET实现还需要提交,显得不怎么即时,还是考虑用JS做吧
      

  3.   

    比如,有一个listbox:
    里面有下面这些选项,
    ------------
    AA
    BB
    CC
    DD
    ……
    ------------
    我想要在选取“DD”之后,listbox的显示变成:
    ------------
    DD
    ……------------
    "DD"显示在页面的首行。
      

  4.   

    function changeListbox(obj1,obj2){
    with(obj1){var nc_z=options[selectedIndex].text;}
    var n=obj2.length;
    obj2.selectedIndex=parseInt(n)-1;
    for (var i=0;i<=obj2.length;i++){
        if (obj2.options[i].text==nc_z){
            obj2.selectedIndex=i;
            return;
        }
             }
    }