Sep 20, 2011

Up and Down List Box Item Java Script In ASP.NET

<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

What is the use of n-tier architecture and 3-tier architecture?

how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture. Some people called it ...