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

Can't extract ASP.NET RadGrid inserted row values

2 Answers 78 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
yerlan
Top achievements
Rank 1
yerlan asked on 16 Sep 2010, 10:12 AM

Hi.

I'm tried to use telerik components (including  OpenAccess) in webApp, and created simple webapplication by instructions in "getting started" section.

RadGrid bound to data via code:

1.private void OnPageLoad(object sender, EventArgs e)
2.{
3.    var lanquages = cachedContext.Languages;
4.    RadGrid.DataSource = lanquages;
5.    RadGrid.DataBind();
6.}

and extracting values (guided by ASP.NET AJAX controls documentation)

1.protected void OnRadGridInsertCommand(object sender, GridCommandEventArgs e)
2.{
3.    GridEditableItem editedItem = e.Item as GridEditableItem;
4.    Hashtable table = new Hashtable();
5.    editedItem.OwnerTableView.ExtractValuesFromItem(table, editedItem);
6.    ...
7.}
after ectracting "table" contains keys for all grid columns, but keys are empty (values = null).

What i'm doing wrong?

P.S.: ASP.NET 4, C# 4.0, MSSQL Express, Telerik 2010Q2

2 Answers, 1 is accepted

Sort by
0
Accepted
Damyan Bogoev
Telerik team
answered on 17 Sep 2010, 01:43 PM
Hi yerlan,

In fact this is the expected behavior of the RadGrid when the DataBind method is called. You should have in mind, that in case you are using simple data binding (i.e. when you are not using the NeedDataSource event) the correct approach is to call the DataBind() method on the first page load when Page.IsPostBack is false and after handling some event (the sort event for example).
You will need to assign a DataSource and rebind the grid after each operation (paging, sorting, editing, etc.) - this is similar to the MS DataGrid behavior.
The best practice here is to bind the grid data within the NeedDataSource event handler:

protected void Page_Init(object sender, EventArgs e)
{
    ...
    this.RadGrid.InsertCommand += new Telerik.Web.UI.GridCommandEventHandler(RadGrid1_InsertCommand);
}
 
 
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    this.RadGrid.DataSource = this.cachedContext.Languages;
}
In this case the ExtractValuesFromItem method should work as expected.
Hope that helps.

Greetings,
Damyan Bogoev
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
0
yerlan
Top achievements
Rank 1
answered on 17 Sep 2010, 01:48 PM

Hi, Damyan.

I'm found this solution, and all works good.

But, in documentation this moment(using NeedDataSource instead classical binding) not accented.

Thanks, Damyan!

Tags
Getting Started
Asked by
yerlan
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
yerlan
Top achievements
Rank 1
Share this question
or