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

Inline Edit In RadGrid Populating Data Using List<Employee> As A DataSource

1 Answer 72 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Maria Ignatius Ephrem
Top achievements
Rank 1
Maria Ignatius Ephrem asked on 04 Nov 2010, 08:52 AM
Hello there,

Please help me its very urgent...
I want to use Inline editing in radgrid. The grid populating data using List<Employee> as a DataSource. I went through the below demo, the same functionality we want to implement. But we are not using datatable rather we are using List<>. Please help me out. The same below demo should work for list<>, thanks in advance.

http://mono.telerik.com/Input/Examples/Common/DataGrid/DefaultCS.aspx

Thanks and Regards,
Ephrem.J

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 09 Nov 2010, 01:59 PM
Hi Maria,

The approach would be exactly the same with a List<Employee> data source. You will only have to modify the UpdateCommand event of the control to update an Employee object instead of a DataRow object:

protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
{
    GridEditableItem editedItem = e.Item as GridEditableItem;
 
    Hashtable newValues = new Hashtable();
    //The GridTableView will fill the values from all editable columns in the hash
    e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
     
    var employeeId = editItem.GetDataKeyValue("EmployeeID");
    Employee employee = //find the employee object to update gived the employeeId
 
    try
    {
        employee.Name = newValues["Name"].ToString();
        employee.Title = newValues["Title"].ToString();
        ...
        //do that for all fields you have edited
    }
    catch (Exception ex)
    {
        changedRow.CancelEdit();
        RadGrid1.Controls.Add(new LiteralControl("Unable to update the data. Reason: " + ex.Message));
        e.Canceled = true;
    }
}

Regards,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Maria Ignatius Ephrem
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or