Can't extract ASP.NET RadGrid inserted row values

Thread is closed for posting
3 posts, 1 answers
  1. yerlan
    yerlan avatar
    18 posts
    Member since:
    Feb 2008

    Posted 16 Sep 2010 Link to this post


    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)
    3.    var lanquages = cachedContext.Languages;
    4.    RadGrid.DataSource = lanquages;
    5.    RadGrid.DataBind();

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

    1.protected void OnRadGridInsertCommand(object sender, GridCommandEventArgs e)
    3.    GridEditableItem editedItem = e.Item as GridEditableItem;
    4.    Hashtable table = new Hashtable();
    5.    editedItem.OwnerTableView.ExtractValuesFromItem(table, editedItem);
    6.    ...
    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. Answer
    Damyan Bogoev
    Damyan Bogoev avatar
    581 posts

    Posted 17 Sep 2010 Link to this post

    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.

    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
  3. yerlan
    yerlan avatar
    18 posts
    Member since:
    Feb 2008

    Posted 17 Sep 2010 Link to this post

    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!

Back to Top