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

Help functions to Radgrid Insert Command

1 Answer 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Auvo
Top achievements
Rank 1
Auvo asked on 23 Feb 2016, 08:07 PM

Hi,

I have used InsertCommand when inserting new rows to the radgrid.

  

protected void grvTasks_InsertCommand(object sender, GridCommandEventArgs e)
{
    var editableItem = ((GridEditableItem)e.Item);
 
    GetTasks();
 
    if (_taskListMain != null)
    {
        Task newTask = new Task(_taskListMain.DataConnections);
 
        Hashtable values = new Hashtable();
        editableItem.ExtractValues(values);
 
        if (values["Name"] != null)
            newTask.Name = (string)values["Name"];
 
        if (values["Description"] != null)
            newTask.Description = (string)values["Description"];
 
        if (values["EstimateInHours"] != null)
            newTask.EstimateInHours = int.Parse(values["EstimateInHours"].ToString());
 
 
        _taskListMain.Tasks.TaskRows.Add(newTask);
        _taskListMain.Tasks.Save();
    }
}

 

I copy data from each field from hashtable to the final class properties. This means lot of rows if there are lot of fields, so I wondering is there another way to copy inserted data from GridEditableItem to final custom class? e.g. Similar function what is use in UpdateCommand ( editableItem.UpdateValues(task);)

 

Regards,

Auvo

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 26 Feb 2016, 12:50 PM
Hi Auvo,

When using manual CRUD operations you need to extract the values entered by the user and update the corresponding fields in the data source.

Alternatively you could use Automatic DataSource operations with RadGrid. Note that automatic operations are available only for declarative DataSource controls. Also, the data source should support automatic operations. Check out the following article for additional information on the feature.



Regards,
Viktor Tachev
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Auvo
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or