开发者

How to display index number and text value in the listbox asp.net c#

I want to display index value along with the text value of the listbox. If we are moving the item up and down the index value remains the same. only the text hast to cha开发者_如何转开发nge.

Code i am using to move the item up and down:

         <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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜