ASP<asp:ListBox ID="ListBox1" runat="server" Height="100px" Width="200px"> <asp:ListItem>台灣</asp:ListItem> <asp:ListItem>日本</asp:ListItem> <asp:ListItem>英國</asp:ListItem> <asp:ListItem>西班牙</asp:ListItem> <asp:ListItem>義大利</asp:ListItem></asp:ListBox><asp:Button ID="Button1" runat="server" Text="向上" /><asp:Button ID="Button2" runat="server" Text="向下" />
.VB
向下
rotected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim index As Integer = ListBox1.SelectedIndex
If index > 0 Then
Dim item As ListItem = ListBox1.Items(index)
ListBox1.Items.RemoveAt(index)
ListBox1.Items.Insert(index - 1, item)
End If
nd Sub
向下
rotected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim index As Integer = ListBox1.SelectedIndex
If index < ListBox1.Items.Count - 1 Then
Dim item As ListItem = ListBox1.Items(index)
ListBox1.Items.RemoveAt(index)
ListBox1.Items.Insert(index + 1, item)
End If
End Sub
沒有留言:
張貼留言