现在的位置: 首页 > 综合 > 正文

Move the Item of ListBox

2013年09月09日 ⁄ 综合 ⁄ 共 637字 ⁄ 字号 评论关闭

.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;
    }
   }

}

抱歉!评论已关闭.