Move the Item of ListBox

来源:互联网 发布:linux lnmp搭建 编辑:程序博客网 时间:2024/04/30 08:28

.aspx

--------------------------------

<asp:ListBox id="ListBox1" style="Z-INDEX: 105; LEFT: 96px; POSITION: absolute; TOP: 344px" runat="server">
    <asp:ListItem Value="a1">a1</asp:ListItem>
    <asp:ListItem Value="a2">a2</asp:ListItem>
    <asp:ListItem Value="a3">a3</asp:ListItem>
   </asp:ListBox>

----------------------------------

.cs

//for 个

private void Button1_Click(object sender, System.EventArgs e){
   if (this.ListBox1.SelectedIndex>=0)
   {
    int i = ListBox1.SelectedIndex;
    if(i>0)
    {
     string values = this.ListBox1.Items[i].Text ;
     this.ListBox1.Items[i].Text = this.ListBox1.Items[i-1].Text ;
     this.ListBox1.Items[i-1].Text = values;
    }
   }

}

原创粉丝点击