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

ExtractValuesFromItem() only works for RadGrid after fresh page load

3 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 26 Apr 2011, 07:01 PM
Well.

Please notice the bold, italicized line in the function below.  It works fine (retrieves NEW, user-modified values from the RadGrid) after a fresh load of the page, but after a postback of the page, it retrieves the OLD values from the RadGrid.

Is there any Telerik-related reason this would happen?  I really have no idea why the postback page works differently than the original page load.

private static void CaptureChangesInGrid(RadGrid targetGrid)
{
    //Loop through each targetgrid item
    foreach (GridDataItem gridRow in targetGrid.MasterTableView.Items)
    {
        Dictionary<object, object> editDict = new Dictionary<object, object>();
        targetGrid.MasterTableView.ExtractValuesFromItem(editDict, (gridRow as GridEditableItem));
        foreach (GridColumn column in targetGrid.MasterTableView.Columns)
        {
            CustomEditableColumn editableCol = column as CustomEditableColumn;
            GridEditableColumn editColumn = editableCol as GridEditableColumn;
            if (editableCol != null)
            {
                //Find the edit control in the given row
                System.Web.UI.Control editItem = editableCol.FindControlInRow(gridRow);
   
                if (editItem == null)
                {
                    throw new ApplicationException("Unable to find edit control in for column: " + editableCol.HeaderText);
                }
                editableCol.CheckControlForChange(editItem, GetValueFromDictionary(editableCol, editDict));
            }
        }
    }
}

Does anyone have a better way of retrieving user-entered values on a RadGrid which works after successive postbacks to the page?  Or is there a way to fix this?

EnableViewState is enabled for the page.

The data entered is required for modifying the appearance of the page (highlighting for errors in entries, etc.) and thus I cannot have a fresh load performed every time.  An undesirable option might be to place any user-edited data into the viewstate and perform a full refresh of the page and replace old data with the saved viewstate data... but that sounds like a lot of additional code for which I really don't have the time to create.

I'll be here all day, talk to me!

Thanks,
Jon

3 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 29 Apr 2011, 02:00 PM
Hello Jon,

It depends where and when you call the CaptureChangesInGrid function. After postback the new values might not have been updated yet at the time you try to extract them. Note that normally the ExtractValuesFromItem method is used in the ItemCommand event when performing manual updates as shown in this help topic. Also another option of getting the newly entered values would be to access the controls inside the particular item and get there values manually as shown in this help topic (section "Accessing the value of cells in edit mode").
It will be helpful if you could post the whole page and code behind so we can have a better idea of how you use this code.

Greetings,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jon
Top achievements
Rank 1
answered on 29 Apr 2011, 09:44 PM
Thanks for the reply.

I looked through those links you posted and I'm afraid the ItemCommand link is of no help since the Update is being performed somewhat-externally to the RadGrid.  The other link about obtaining the values manually looked promising, but required the individual Items to be in edit mode, and I'm not sure any of them are in edit mode, but that each Item (row) in the RadGrid contains other Items (columns), some of which contain Controls which are used for edits.

You ask for all the code but I apologize as I cannot freely share said information.  I have posted elsewhere and added what code I could to help explain the problem.  Please look at this thread for more information.  It really seems like I'm so close to hitting the solution, I'm just blindly shooting in the dark right now.

Thanks,
Jon
0
Marin
Telerik team
answered on 02 May 2011, 01:34 PM
Hello Jon,

The ExtractValuesFromItem method is intended for use with items in edit mode (i.e. when they are about to be updated). You need to use different approaches for extracting the values when the item is in edit mode and when it is in display mode, because there might be different controls in the cells with different structure etc. You can access the value of the cell in display mode by first getting reference to the cell as shown in the beginning of the previously mentioned help topic :

TableCell cell = dataItem["ColumnUniqueName"];
and then getting its text (if it is a GridBoundColumn) or getting the controls inside it and extracting the value from there.
When the item is in edit mode you can use the two approaches mentioned in my previous post: with ExtractValuesFromItem or manually accessing the values as shown in the help topic.
You can also have a look at the following demos showing how to access values in the cells in display mode and when updating:
Grid / Accessing Cells and Rows
Extracting values Using Server-side API
You can also check whether an item is in edit mode using its IsInEditMode property.

Kind regards, Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Marin
Telerik team
Jon
Top achievements
Rank 1
Share this question
or