<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<input type="button" value="Up"onclick="moveUp(this.form['_lb2']);" />
<asp:ListBox ID="_lb2" name="_lb2" runat="server" Height="100px" Width="170px">
<asp:ListItem>Data1</asp:ListItem>
<asp:ListItem>Data2</asp:ListItem>
<asp:ListItem>Data3</asp:ListItem>
<asp:ListItem>Data4</asp:ListItem>
</asp:ListBox>
<input type="button" value="Down"onclick="moveDown(this.form['_lb2']);" />
<div>
<br />
</div>
</form>
</body>
<script type="text/javascript">
function moveUp(sel)
{
var idx = sel.selectedIndex;
var opt;
// Only move up if not first
if (idx > 0)
{
opt = sel.options[idx];
sel.insertBefore(opt, sel.options[--idx]);
}
}
function moveDown(sel)
{
var idx = sel.selectedIndex;
var opt;
// Only move up if not first
if (idx < sel.length-1)
{
opt = sel.options[idx];
sel.insertBefore(sel.options[++idx],opt);
}
}
</script>
</html>
No comments:
Post a Comment