I have a Telerik RadGrid which allows the user to drag rows to reorder them. What will happen on the server side is an int column for each row will be modified based on where they've dragged, then we sort on this figure on the screens.
What I can't figure out is the easiest way to handle the reordering in the code behind. What's the easiest/best way of updating incrementing/decrementing any rows 'inbetween' the dragged rows?
EDIT: What I have so far
//We should only allow one section to be dragged at a time
GridDataItem draggedItem = e.DraggedItems.Single();
TakeoffSection draggedSection = dc.TakeoffSections.Where(a => a.ID == (long)draggedItem.GetDataKeyValue("ID")).Single();
int origDragSectNo = draggedSection.SectionNo;
GridDataItem destItem = e.DestDataItem;
TakeoffSection destSection = dc.TakeoffSections.Where(a => a.ID == (long)destItem.GetDataKeyValue("ID")).Single();
int origDestSectNo = destSection.SectionNo;
if (e.DropPosition == GridItemDropPosition.Above)
{
if (draggedSection.SectionNo < destSection.SectionNo)
{
//They are dragging *down*!
draggedSection.SectionNo = destSection.SectionNo;
destSection.SectionNo++;
foreach (var item in dc.TakeoffSections.Where(a => a.RevisionID == ActiveRevisionID && a.SectionNo < origDestSectNo && a.SectionNo > origDestSectNo))
item.SectionNo--;
dc.SubmitChanges();
}
else
{
//They are dragging *up*
}
}