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

radgrid updatecommand has old values in GridEditableItem

0 Answers 220 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sohaib
Top achievements
Rank 1
sohaib asked on 14 Jun 2011, 08:33 AM
i am having a similar problem, i am binding my radgrid to a datatable created manually after converting an xml to datatable, but update command doest give updated values,

here is my grid code

<telerik:RadGrid runat="server" ID="gvTable" AllowPaging="True" Skin="Vista" PageSize="100"
            AllowSorting="True" ClientSettings-DataBinding-EnableCaching="true" GridLines="None"
            AutoGenerateEditColumn="True" AutoGenerateDeleteColumn="True"
            AllowAutomaticUpdates="False" OnUpdateCommand="gvTable_UpdateCommand"
            OnInsertCommand="gvTable_InsertCommand"
             AllowAutomaticDeletes="True"
            AllowAutomaticInserts="True" onneeddatasource="gvTable_NeedDataSource">
            <ExportSettings FileName="Order Details" IgnorePaging="True" ExportOnlyData="true">
            </ExportSettings>
            <ClientSettings EnableRowHoverStyle="True" Selecting-AllowRowSelect="true">
                <DataBinding EnableCaching="True">
                </DataBinding>
                <Selecting AllowRowSelect="True"></Selecting>
            </ClientSettings>
            <MasterTableView InsertItemPageIndexAction="ShowItemOnCurrentPage" EnableHeaderContextMenu="True"
                CommandItemDisplay="Top" EditMode="InPlace" DataKeyNames="">
                <CommandItemSettings ShowExportToExcelButton="true" AddNewRecordText="" ShowAddNewRecordButton="False" />
                <Columns>
                </Columns>
                <HeaderStyle Font-Bold="False" />
            </MasterTableView>
            <PagerStyle Mode="NextPrevAndNumeric" />
        </telerik:RadGrid>

here is where i am assigning the datatable to grid on button click

        this.gvTable.DataSource = dataTable;
        Session["DataSource"] = dataTable;
        this.gvTable.MasterTableView.DataKeyNames = GetColNames(dataTable); // Gets the column names of the datatable and returns as string[]
        this.gvTable.DataBind();

here is the pageload event, its empty

protected void Page_Load(object sender, EventArgs e)
    {
}

here is the need datasource

protected void gvTable_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    DataTable dt = this.GridSource;
    this.gvTable.DataSource = dt;
    this.gvTable.MasterTableView.DataKeyNames = GetColNames(dt);
}

here is the gvTable_UpdateCommand
protected void gvTable_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
 
        GridEditableItem editedItem = e.Item as GridEditableItem;
        DataTable ordersTable = this.GridSource;
        //Locate the changed row in the DataSource
        DataRow[] changedRows = ordersTable.Select("col1 = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["col1"].ToString());
        //editedItem["Item"].Controls[0]
        if (changedRows.Length != 1)
        {
            this.Label1.Text += "Unable to locate the Order for updating.";
            e.Canceled = true;
            return;
        }
        //Update new values
        Hashtable newValues = new Hashtable();
        e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
        changedRows[0].BeginEdit();
        try
        {
            foreach (DictionaryEntry entry in newValues)
            {
                changedRows[0][(string)entry.Key] = entry.Value;
            }
            changedRows[0].EndEdit();
            Label1.Text = "Successfully updated";
        }
        catch (Exception ex)
        {
            changedRows[0].CancelEdit();
            Label1.Text += "Unable to update Orders. Reason: " + ex.Message;
            e.Canceled = true;
        }
    }

PROBLEM:
editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["col1"].ToString()
this line in the above function always gives old values, cant figure out why, please help, thanks


i have used the code from this page
http://www.telerik.com/help/aspnet-ajax/grid-updating-inplace-and-editforms.html

No answers yet. Maybe you can help?

Tags
Grid
Asked by
sohaib
Top achievements
Rank 1
Share this question
or