MovingUp and MoveDown in ListBox webFom

sureshcd10

Regular
Joined
Dec 25, 2003
Messages
77
I ve placed one ListBox control on my webForm thich displays the listitems

ListItem1
ListItem2
ListItem3

and I placed two Command buttons one is labeld as MoveUp and Other Button is labeled as Move down.Now I selected ListItem2 and Clicked on the MoveUp button.I wanted to Move listItem2 to the position of ListItem1.and ListItem1 to ListItem2's Position.How can I do this.Plz help me.I m using ASP.NET and VB.net :confused: :(
 
sureshcd10 said:
I ve placed one ListBox control on my webForm thich displays the listitems

ListItem1
ListItem2
ListItem3

and I placed two Command buttons one is labeld as MoveUp and Other Button is labeled as Move down.Now I selected ListItem2 and Clicked on the MoveUp button.I wanted to Move listItem2 to the position of ListItem1.and ListItem1 to ListItem2's Position.How can I do this.Plz help me.I m using ASP.NET and VB.net :confused: :(
like this???

<SCRIPT>

function swap(oldI, newI)
{
var tempTxt = Select1.options(oldI).text;
var tempVal = Select1.options(oldI).value;
Select1.options(oldI).text = Select1.options(newI).text;
Select1.options(oldI).value = Select1.options(newI).value;
Select1.options(newI).text = tempTxt;
Select1.options(newI).value = tempVal;
Select1.selectedIndex = newI;
onChangeHandler()
}

function swapListItem(btn)
{
if (btn == btnUp)
swap(Select1.selectedIndex, Select1.selectedIndex-1);
else
swap(Select1.selectedIndex, Select1.selectedIndex+1);
}

function onChangeHandler()
{
btnUp.disabled = Select1.selectedIndex == 0;
btnDown.disabled = Select1.selectedIndex == (Select1.options.length-1);
}

</SCRIPT>

<body>
<SELECT id="Select1" style="WIDTH: 220px; HEIGHT: 176px" size="11" name="Select1" onchange="onChangeHandler()">
<OPTION value="1">ListItem1</OPTION>
<OPTION value="2">ListItem2</OPTION>
<OPTION value="3">ListItem3</OPTION>
</SELECT>
<br>
<INPUT id="btnUp" type="button" value="Move Up" name="btnUp" disabled onclick=swapListItem(this)>
<INPUT id="btnDown" type="button" value="Move Down" name="btnDown" disabled onclick=swapListItem(this)>
</body>
 
Back
Top