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

[Solved] Customized command item for multiple row selection

1 Answer 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
omair
Top achievements
Rank 1
omair asked on 16 Jun 2009, 05:57 PM
Hello,

I know usual command item actions such as add new, edit, delete, refresh are built in with Rad grid. These can be performed on multiple row selection as well with some twists in the aspx and code behind files.

But, I want to acheive a customized command item for multiple row selection such as changing status of the row by selecting multiple rows and click on "Change status" button. I can include this button in the CommandItemTemplate. I can perform basic marching thru selected Items also. How do I convert my selected rows back into DTO - data transfer objections?

Thanks a lot in advance.

 

 

 
   
protected void BuildingItemList_ItemCommand(object source, GridCommandEventArgs e)     
{   
    if (e.CommandName.ToUpper() == "CHANGESTATUS")    
    {   
        foreach (GridDataItem dataItem in BuildingItemList.SelectedItems)   
         {   
            // Todo - something like below to convert selected items into an object.  
            // MyDTO dto = (MyDTO) dataItem.DataItem;   
         }  
    }   
}  
 
 
 

 

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 18 Jun 2009, 11:17 AM
Hi omair,

The most suitable approach we recommend is to create a new DTO object in your code and set its values manually, reading them from RadGrid's items. This will ensure proper initialization of your DTO object. DataItem values can be read by referring to the required column by its unique name, reading its Text property and converting it to the required format:

DateTime date = DateTime.Parse((item as GridDataItem)["DateColumn"].Text); 

The above example assumes item is a reference to a data GridDataItem fro MasterTableView's Items collection and its column with unique name "DateColumn" contains a value that can be converted to a DateTime object.

Kind regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
omair
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or