This is a migrated thread and some comments may be shown as answers.

How to move a row from one group to another group in Rad Grid.

3 Answers 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Abhi Shinde
Top achievements
Rank 1
Abhi Shinde asked on 19 Jan 2011, 07:38 AM
Hi,
        I am using radGrid. My radGrid contain all posted "Questions" and Group by "Question Category".
I want to reorder questions and update it into database. 
Reordering is working fine for same category BUT if i drop a row from one category to another, it wont work.

here, after dropping a row, how can i get destination "categoryID"....?????
  
(in grid itself, I want to move a question from one category to another category. )


protected void rgQuestions_RowDrop(object sender, GridDragDropEventArgs e)
    {
        if (e.DestDataItem != null && e.DestDataItem.OwnerGridID == rgQuestions.ClientID)
        {
            //reorder items in pending grid
            IList<Question> questions = Questions;
            Question order = GetQuestion(questions, (Int64)e.DestDataItem.GetDataKeyValue("Q_QuestionId"));
            int destinationIndex = questions.IndexOf(order);
  
            if (e.DropPosition == GridItemDropPosition.Above && e.DestDataItem.ItemIndex > e.DraggedItems[0].ItemIndex)
            {
                destinationIndex -= 1;
            }
            if (e.DropPosition == GridItemDropPosition.Below && e.DestDataItem.ItemIndex < e.DraggedItems[0].ItemIndex)
            {
                destinationIndex += 1;
            }
  
            List<Question> ordersToMove = new List<Question>();
            foreach (GridDataItem draggedItem in e.DraggedItems)
            {
                Question tmpOrder = GetQuestion(questions, (Int64)draggedItem.GetDataKeyValue("Q_QuestionId"));
                if (tmpOrder != null)
                    ordersToMove.Add(tmpOrder);
            }
              
  
            foreach (Question orderToMove in ordersToMove)
            {
                questions.Remove(orderToMove);
  
                questions.Insert(destinationIndex, orderToMove);
            }
            Questions = questions;
            rgQuestions.Rebind();
  
            foreach (GridDataItem item in rgQuestions.MasterTableView.Items)
            {
                Question tmpOrder = GetQuestion(questions, (Int64)item.GetDataKeyValue("Q_QuestionId"));
  
                string strQry = "Update Assess_QuestionMaster set Q_Order='"+ item.ItemIndex.ToString() +"' where Q_Questionid='" + tmpOrder.Q_QuestionId +"'";
                MySQL.ExecuteSQL(strQry);
  
            }
            rgQuestions.Rebind();
            int destinationItemIndex = destinationIndex - (rgQuestions.PageSize * rgQuestions.CurrentPageIndex);
            e.DestinationTableView.Items[destinationItemIndex].Selected = true;
        }
    }


plsss reply .....
Thanks 




protected void rgQuestions_RowDrop(object sender, GridDragDropEventArgs e)
    {
        if (e.DestDataItem != null && e.DestDataItem.OwnerGridID == rgQuestions.ClientID)
        {
            //reorder items in pending grid
            IList<Question> questions = Questions;
            Question order = GetQuestion(questions, (Int64)e.DestDataItem.GetDataKeyValue("Q_QuestionId"));
            int destinationIndex = questions.IndexOf(order);
 
            if (e.DropPosition == GridItemDropPosition.Above && e.DestDataItem.ItemIndex > e.DraggedItems[0].ItemIndex)
            {
                destinationIndex -= 1;
            }
            if (e.DropPosition == GridItemDropPosition.Below && e.DestDataItem.ItemIndex <e.DraggedItems[0].ItemIndex)
            {
                destinationIndex += 1;
            }
 
            List<Question> ordersToMove = new List<Question>();
            foreach (GridDataItem draggedItem in e.DraggedItems)
            {
                Question tmpOrder = GetQuestion(questions, (Int64)draggedItem.GetDataKeyValue("Q_QuestionId"));
                if (tmpOrder != null)
                    ordersToMove.Add(tmpOrder);
            }
             
 
            foreach (Question orderToMove in ordersToMove)
            {
                questions.Remove(orderToMove);
 
                questions.Insert(destinationIndex, orderToMove);
            }
            Questions = questions;
            rgQuestions.Rebind();
 
            foreach (GridDataItem item in rgQuestions.MasterTableView.Items)
            {
                Question tmpOrder = GetQuestion(questions, (Int64)item.GetDataKeyValue("Q_QuestionId"));
 
                string strQry = "Update Assess_QuestionMaster set Q_Order='"+ item.ItemIndex.ToString() +"' where Q_Questionid='" + tmpOrder.Q_QuestionId +"'";
                MySQL.ExecuteSQL(strQry);
 
            }
            rgQuestions.Rebind();
            int destinationItemIndex = destinationIndex - (rgQuestions.PageSize * rgQuestions.CurrentPageIndex);
            e.DestinationTableView.Items[destinationItemIndex].Selected = true;
        }
    }

3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 21 Jan 2011, 03:01 PM
Hello Abhi,

In order to achieve your goal, you need to handle the RowDrop server-side event as you already found. There make sure you have updated the Category field for the dropped row record to the Category of the destination row and rebind the grid.

Best wishes,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Abhi Shinde
Top achievements
Rank 1
answered on 22 Jan 2011, 10:18 AM
off-course I want to pass the categoryID but My question is that, How can I get destination categoryID.??    
0
Iana Tsolova
Telerik team
answered on 24 Jan 2011, 03:31 PM
Hi,

In the RowDrop event handler e.DestinationItem is a reference to the destination item. The you can get the CategoryId as below if where CategoryId is the UniqueName of the CategoryId column:

e.DestinationItem["CategoryId"].Text.

For more information on accessing grid cells and row, refer to this article.

Greetings,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Abhi Shinde
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Abhi Shinde
Top achievements
Rank 1
Share this question
or