如何在列表框asp.net c#中显示索引号和文本值

时间:2011-07-19 04:22:28

标签: c# asp.net listbox

我想显示索引值以及列表框的文本值。如果我们上下移动项目,则索引值保持不变。只有文字才能改变。

我用来上下移动项目的代码:

         <script type="text/javascript" language="Javascript">
       function MoveUp() {
           var con = document.getElementById("lbRank");
           if (con.selectedIndex >= 0) {
               for (var count = 1; count < con.options.length; count++) {
                   if (con.options[count].selected == true) {
                       var tem = con.options[count].text;
                       con.options[count].text = con.options[count - 1].text;
                       if (con.options[count - 1].selected == false) {
                           con.options[count].selected = false;
                       }
                       con.options[count - 1].selected = true;
                       con.options[count - 1].text = tem;
                   }
               }
           }
           else {
               alert('Select any item');
           }

       }

       function MoveDown() {
           var con = document.getElementById("lbRank");
           if (con.selectedIndex >= 0) {
               for (var count = con.options.length - 2; count >= 0; count--) {
                   if (con.options[count].selected == true) {
                       var tem = con.options[count].text;
                       con.options[count].text = con.options[count + 1].text;
                       if (con.options[count + 1].selected == false) {
                           con.options[count].selected = false;
                       }
                       con.options[count + 1].selected = true;
                       con.options[count + 1].text = tem;
                   }
               }
           }
           else {
               alert('Select any item');
           }
       }
</script>

0 个答案:

没有答案