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

Telerik Grid Update Command

5 Answers 590 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Suderson
Top achievements
Rank 1
Suderson asked on 09 May 2011, 06:34 AM

Hi All,

 

I'm using Telerik Grid and binded an XML through dataset. I've a autyo generate edit coulmn.

 When I press edit, I get a text box with exisitng value and update, cancel button. After typing new value whren i press am not getting the new value in the grid. Can any one help on this. I'm using updatecommand event,but no use so far. Here is my code

 

 Hashtable newValues = new Hashtable();
            ((GridEditableItem)e.Item).ExtractValues(newValues);

            GridEditableItem editItem = (GridEditableItem)e.Item;
            GridEditableItem editedItem = e.Item as GridEditableItem;
            GridEditManager editMan = editedItem.EditManager;

            var obj = editItem.GetDataKeyValue("ConnectionString");

            //TextBox txt = e.Item.FindControl("txtValue") as TextBox;
            //if (txt != null)
            //{
            //    string s = txt.Text;
            //}
            ds.Tables["add"].Rows[editItem.DataSetIndex][1] = "XXXXX";
            //radDisplay.DataSource = ds.Tables["add"];
            radDisplay.Rebind();
            StringWriter sw = new StringWriter();
            ds.WriteXml(sw);
            Session["decryptesXMLString"] = sw.ToString();

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 May 2011, 08:11 AM
Hello Suderson,

I have tried to recreate the same at my end but no avail. Check out the folowing help article which explains more on the ExtractValuesFromItem.
Updating values using UserControl/FormTemplate.

Another suggession is to access the control as follows.
C#:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
 {
   if ((e.Item is  GridEditFormItem) && (e.Item.IsInEditMode))
       {
           GridEditFormItem edititem = (GridEditFormItem)e.Item;
           TextBox txtbx = (TextBox)edititem.FindControl("txtValue");//accessing the textBox
       }
}

Thanks,
Princy.
0
Suderson
Top achievements
Rank 1
answered on 09 May 2011, 12:13 PM
Tried it also.

No use. Still getting the old values. I used the GridButtonColumn also. Still no use. I'm frustrated with this?
0
Kenneth Miller
Top achievements
Rank 1
answered on 09 May 2011, 02:40 PM
I am having the same problem, with the following code, using a RadGrid set up for automatic operations.

        Dim editItem As GridEditFormItem = CType(e.Item, GridEditFormItem)
        Dim ItemClass As String = (TryCast(editItem("ItemClass").Controls(0), TextBox)).Text

Clicking the "Edit" link in the first column drops the form down. I can type in the resulting text box, but after clicking "Update" a breakpoint check shows me the original value, not what I just entered

I am also using a RadAjaxproxyManager. Clicking "Update" shows me the ajax update indicator, but also immediately wipes out my edited changes and restores the original value.

I do not currently have any query actually doing the update; I simply stop at a breakpoint to see what value has been extracted.



0
Suderson
Top achievements
Rank 1
answered on 10 May 2011, 01:31 PM
Hi I Found the solution for my problem. Please have a look into it.

While Page Load, please do not give databind() of gird. The need source event will take care of it. Please check your code.

All the best!!!
0
sohaib
Top achievements
Rank 1
answered on 14 Jun 2011, 08:25 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

Tags
Grid
Asked by
Suderson
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Suderson
Top achievements
Rank 1
Kenneth Miller
Top achievements
Rank 1
sohaib
Top achievements
Rank 1
Share this question
or