السلام عليكم
اشعر انه يوجد حل ابسط من
المشروع في المرفق
انا استعمل كنترولات DevExpress
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Session["opersons"] == null)
{
List<person> opersons = new List<person>();
opersons.Add(new person { Index = 1, Name = "A" });
opersons.Add(new person { Index = 2, Name = "B" });
opersons.Add(new person { Index = 3, Name = "C" });
opersons.Add(new person { Index = 4, Name = "D" });
opersons.Add(new person { Index = 5, Name = "E" });
opersons.Add(new person { Index = 6, Name = "F" });
Session["opersons"] = opersons;
}
}
GvPersonsRefresh(0);
}
private class person
{
public int Index { get; set; }
public string Name { get; set; }
}
protected void btnFirst_Click(object sender, EventArgs e)
{
/*get select rank */
int ind = (int)gvPersons.GetRowValues(gvPersons.FocusedRowIndex, "Index");
List<person> opersons = (List<person>)Session["opersons"];
opersons = opersons.OrderBy(x => x.Index).ToList<person>();
if (ind == 1) return;
/* حفض السطر المحدد في ابجكة و السطر السابق في ابجكة اخر */
person opersonFrom = opersons.Where(x => x.Index == ind).ToList<person>()[0];
int i = 2;
foreach (person col in opersons)
{
if (col == opersonFrom)
col.Index = 1;
else
{
col.Index = i;
i++;
}
}
/* فحفض القاءمة الجديدة في السيشن*/
Session["opersons"] = opersons;
/* عرض النتيجة في القريد فيو*/
GvPersonsRefresh(0);
}
protected void btnUp_Click(object sender, EventArgs e)
{
/*استرجاع قيمة اندكس المحدد */
int index = gvPersons.FocusedRowIndex;
int ind = (int)gvPersons.GetRowValues(gvPersons.FocusedRowIndex, "Index");
if (ind == 1) return;
List<person> opersons = (List<person>)Session["opersons"];
/* حفض السطر المحدد في ابجكة و السطر السابق في ابجكة اخر */
person opersonFrom = opersons.Where(x => x.Index == ind).ToList<person>()[0];
person oColumnTo = opersons.Where(x => x.Index == ind - 1).ToList<person>()[0];
opersonFrom.Index = ind - 1;
oColumnTo.Index = ind;
/* تغير اماكن الابجكة */
opersons.Where(x => x.Index == ind).ToList<person>()[0] = opersonFrom;
opersons.Where(x => x.Index == ind - 1).ToList<person>()[0] = oColumnTo;
/* فحفض القاءمة الجديدة في السيشن*/
Session["opersons"] = opersons;
/* عرض النتيجة في القريد فيو*/
GvPersonsRefresh(index + 1);
}
protected void btnDown_Click(object sender, EventArgs e)
{
/*استرجاع قيمة اندكس المحدد */
int index = gvPersons.FocusedRowIndex;
int ind = (int)gvPersons.GetRowValues(gvPersons.FocusedRowIndex, "Index");
List<person> opersons = (List<person>)Session["opersons"];
if (ind == opersons.Count) return;
/* حفض السطر المحدد في ابجكة و السطر التالي في ابجكة اخر */
person opersonFrom = opersons.Where(x => x.Index == ind).ToList<person>()[0];
person oColumnTo = opersons.Where(x => x.Index == ind + 1).ToList<person>()[0];
opersonFrom.Index = ind + 1;
oColumnTo.Index = ind;
/* تغير اماكن الابجكة */
opersons.Where(x => x.Index == ind).ToList<person>()[0] = opersonFrom;
opersons.Where(x => x.Index == ind - 1).ToList<person>()[0] = oColumnTo;
/* فحفض القاءمة الجديدة في السيشن*/
Session["opersons"] = opersons;
/* عرض النتيجة في القريد فيو*/
GvPersonsRefresh(index-1);
}
protected void btnLast_Click(object sender, EventArgs e)
{
/*get select rank */
int ind = (int)gvPersons.GetRowValues(gvPersons.FocusedRowIndex, "Index");
List<person> opersons = (List<person>)Session["opersons"];
opersons = opersons.OrderBy(x => x.Index).ToList<person>();
if (ind == opersons.Count) return;
/* حفض السطر المحدد في ابجكة و السطر السابق في ابجكة اخر */
person opersonFrom = opersons.Where(x => x.Index == ind).ToList<person>()[0];
int i = 1;
foreach (person col in opersons)
{
if (col == opersonFrom)
col.Index = opersons.Count;
else
{
col.Index = i;
i++;
}
}
/* فحفض القاءمة الجديدة في السيشن*/
Session["opersons"] = opersons;
/* عرض النتيجة في القريد فيو*/
GvPersonsRefresh(opersons.Count);
}
private void GvPersonsRefresh(int Rowindex )
{
gvPersons.DataSource = (List<person>)Session["opersons"];
gvPersons.DataBind();
gvPersons.SortBy(gvPersons.Columns["Index"], ColumnSortOrder.Ascending);
gvPersons.FocusedRowIndex = Rowindex;
}
}
}شكرا على المساعدة