using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Test_Sort : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
void Page_PreRender(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
//Up
protected void LinkButton1_Click(object sender, EventArgs e)
{
//올라갈거와 내려갈꺼를 찾아서 다시 제정렬
if (this.ListBox1.SelectedIndex <= 0) {
return;
}
int up_item_num = this.ListBox1.SelectedIndex;
int down_item_num = this.ListBox1.SelectedIndex-1;
//------------------------------------------------------------------------------------------------
// 한단계 올리기
//------------------------------------------------------------------------------------------------
ListItem up = this.ListBox1.Items[up_item_num];
ListItem down = this.ListBox1.Items[down_item_num];
//올리기 전에 백업 데이터가 바뀌어버리가 때문에
string temp_Value = this.ListBox1.Items[down_item_num].Value;
string temp_Text = this.ListBox1.Items[down_item_num].Text;
this.ListBox1.Items[down_item_num].Value = up.Value;
this.ListBox1.Items[down_item_num].Text = up.Text;
this.ListBox1.Items[up_item_num].Value = temp_Value;
this.ListBox1.Items[up_item_num].Text = temp_Text;
this.ListBox1.SelectedIndex = down_item_num;
}
//Down
protected void LinkButton2_Click(object sender, EventArgs e)
{
//------------------------------------------------------------------------------------------------
// 한단계 내리기
//------------------------------------------------------------------------------------------------
int wantNum = this.ListBox1.SelectedIndex+1;
//Response.Write("this.ListBox1.SelectedIndex=" + this.ListBox1.SelectedIndex.ToString() + "////" + this.ListBox1.Items.Count.ToString());
if (this.ListBox1.Items.Count <= wantNum)
{
return;
}
//내려가고싶은
int down_item_num = this.ListBox1.SelectedIndex;
//올라가야할
int up_item_num = this.ListBox1.SelectedIndex + 1;
ListItem down = this.ListBox1.Items[down_item_num];
ListItem up = this.ListBox1.Items[up_item_num];
//내리기 전에 백업 데이터가 바뀌어버리가 때문에
string temp_Value = this.ListBox1.Items[up_item_num].Value;
string temp_Text = this.ListBox1.Items[up_item_num].Text;
this.ListBox1.Items[up_item_num].Value = down.Value;
this.ListBox1.Items[up_item_num].Text = down.Text;
this.ListBox1.Items[down_item_num].Value = temp_Value;
this.ListBox1.Items[down_item_num].Text = temp_Text;
this.ListBox1.SelectedIndex = up_item_num;
}
private void InsertSortList()
{
}
}