Reputation: 3415
I am trying to use the drag re-ordering on my radgrid. The code I have works well for me (it fires on the RowDrop event) but my client cant get it to work and I have troubleshooted it down to show that when he does the drop, the DestDataItem property of the args is null, so the drop logic never triggers?!? here is my code:
protected void questionGrid_RowDrop(object sender, GridDragDropEventArgs e)
{
if (e.DestDataItem != null)
{
int tempId = int.Parse(editingId.Value);
theTemplate = ent.SurveyTemplates.Where(i => i.Id == tempId).FirstOrDefault();
int id = int.Parse(e.DraggedItems[0]["Id"].Text);
SurveyQuestion draggedQuestion = ent.SurveyQuestions.Where(i => i.Id == id).FirstOrDefault();
List<SurveyQuestion> tempArray = theTemplate.Questions.OrderBy(i => i.Rank).ToList();
tempArray.Remove(draggedQuestion);
tempArray.Insert(e.DestDataItem.ItemIndex, draggedQuestion);
int j = 0;
foreach (SurveyQuestion sq in tempArray)
{
sq.Rank = j;
j++;
}
ent.SaveChanges();
questionGrid.Rebind();
}
else
{
Exceptions.LogException(new Exception("NULL DEST"));
}
}
It just references the dragged item and pulls it from the list of items and re-inserts it at the new index, then it updates the rank property of each item to its new index and saves.
Why would this work for me and not for him? Could this server side code be bothered by browser differences?
Upvotes: 0
Views: 2402
Reputation: 3694
As mentioned in this thread, if the item isn't dropped on an actual data row in the grid, the DestDataItem will be null.
You can prevent your RowDrop event from firing, if the target isn't a data row, by handling the OnRowDropping event on the client side and ignoring the things you don't want:
function gridRowDropping(sender, args)
{
if (!args.get_targetGridDataItem())
args.set_cancel(true);
}
Upvotes: 1