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

[Solved] Can't get RadGrid's ExtractValuesFromItem to work

2 Answers 286 Views
Grid
This is a migrated thread and some comments may be shown as answers.
bemara57
Top achievements
Rank 1
bemara57 asked on 15 Apr 2008, 11:37 PM
I'm a little new at this- but I'm trying to update my MembershipUser via the built-in EditForm in the RadGrid, but it's not taking any of my edits. It doesn't produce any errors, it just updates the user with the same exact info as before, ignoring my changes. What am I doing wrong? I'd greatly appreciate any help or direction.

    protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    { 
        // Get edited row 
        GridEditableItem editedItem = e.Item as GridEditableItem; 
         
        // Get primary key of editted item 
        object dataKey = editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ProviderUserKey"]; 
 
        //Locate the changed row in the data source 
        MembershipUser liveUser = membershipProvider.GetUser(dataKey, false); 
 
        // Check if user still exists in data source 
        if (liveUser == null
        { 
            statusLabel.Text += "Unable to locate the user for updating."
            e.Canceled = true
            return
        } 
 
        // Update new values 
        Hashtable newValues = new Hashtable(); 
 
        // The GridTableView will fill the values from all editable columns in the hash 
        editedItem.OwnerTableView.ExtractValuesFromItem(newValues, editedItem); 
 
        try 
        { 
            // Update user object with form data 
            liveUser.Email = (string)newValues["Email"]; 
 
            membershipProvider.UpdateUser(liveUser); 
            statusLabel.Text += "User " + liveUser.UserName + " updated."
        } 
        catch (Exception ex) 
        { 
            statusLabel.Text += "Unable to update user. Reason: " + ex.Message + "."
            e.Canceled = true
        } 
 
        // Refresh grid view data 
        RadGrid1.Rebind(); 
    } 

2 Answers, 1 is accepted

Sort by
0
Konstantin Petkov
Telerik team
answered on 16 Apr 2008, 03:04 PM
Hello bemara57,

Rebinding the Grid is not necessary. You can comment the last line to check if this is causing the problem.

Otherwise the example online here:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/DataEditing/ExtractValues/DefaultCS.aspx

seems to update the Grid records. I hope comparing the code will help you resolve the problem.

Greetings,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
bemara57
Top achievements
Rank 1
answered on 16 Apr 2008, 11:28 PM
Thanks but I found that it was a timing issue. First I did this (which made the grid go all blank when I clicked anything like the edit button):

    protected void Page_Load(object sender, EventArgs e)
    {    
        if (!Page.IsPostBack)
        {
            RadGrid1.DataSource = membershipProvider.GetAllUsers();
            RadGrid1.DataBind();
        }
    }


I had to do this to get it working:
    protected override void OnPreRender(EventArgs e)
    {
        RadGrid1.DataSource = membershipProvider.GetAllUsers();
        RadGrid1.DataBind();

        base.OnPreRender(e);
    }
Tags
Grid
Asked by
bemara57
Top achievements
Rank 1
Answers by
Konstantin Petkov
Telerik team
bemara57
Top achievements
Rank 1
Share this question
or