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

[Solved] Telerik Rad Grid: How to find out old/original values in edit mode

7 Answers 774 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DC
Top achievements
Rank 1
DC asked on 16 Nov 2009, 03:56 PM

Hi,
I am using telerik radgrid with EditMode="InPlace".Grid is bound to list of transaction objects as shown below in server side code section. I have a GridDropDownColumn which shows local currency for transactions. When I click on "edit" button which is generated as GridEditCommandColumn, I get the row in edit mode and list of currencies in the dropdown (GridDropDownColumn). But when grid is in edit mode, I need to set the previous/old value in the dropdownlist and I am unable to do that. What I need to know is how to find out old values when grid is in edit mode so that I can set selectedvlaue in dropdownlist. Is there any Server Side API which can help me out?

Following is the declaration of radgrid on aspx page.
//Design time code
<telerik:RadGrid ID="rgGLAdjustments" runat="server" AllowExportToExcel="true"
                        Width="100%" OnDeleteCommand="rgGLAdjustments_DeleteCommand" OnNeedDataSource="rgGLAdjustments_NeedDataSource"
                        OnItemDataBound="rgGLAdjustments_ItemDataBound" OnEditCommand="rgGLAdjustments_EditCommand">
<MasterTableView DataKeyNames="TransactionID" EditMode="InPlace">
                            <Columns>
<%--Some GridBoundColumns are here--%>
<telerik:GridDropDownColumn UniqueName="LocalCurrency" HeaderText="Local Currency"
                                    DropDownControlType="DropDownList" DataField="LocalCurrency" ListDataMember="GetDataTable"
                                    ListValueField="LocalCurrency" ListTextField="LocalCurrency">
                                </telerik:GridDropDownColumn>

<telerik:GridEditCommandColumn UpdateText="Update" UniqueName="EditCommandColumn"
                                    CancelText="Cancel" EditText="Edit">
</Columns>
                        </MasterTableView>
                    </telerik:RadGrid>

"GetDataTable" is the property on my aspx.cs which returns a datatable and I bind that datatable to dropdowlist in "rgGLAdjustments_ItemDataBound" event handler as shown below

//Server side code
    protected void rgGLAdjustments_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            GridEditManager editMan = editedItem.EditManager;
            GridDropDownListColumnEditor editor = editMan.GetColumnEditor("LocalCurrency") as GridDropDownListColumnEditor;

            //Tried following but it is always null
           //editedItem.SavedOldValues

            editor.DataSource = this.GetDataTable;
            editor.DataValueField = "LocalCurrency";
            editor.DataTextField = "LocalCurrencyValue";
            editor.DataBind();
        }
    }
protected void rgGLAdjustments_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        this.rgGLAdjustments.DataSource = this.TransactionObjectsCollection;
    }

Grid is bound to List of transaction objects in "OnNeedDataSource" handler as shown above.

I tried "editedItem.SavedOldValues" in the above server side code but it is always null. I also tried it in "OnEditCommand" handler but same result. Please advice.

Thanks

7 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 18 Nov 2009, 02:14 PM
Hi,

Please take a look at this help topic (Customizing the options for GridDropDownColumn on editing
section) which elaborates on how to achieve the desired by you functionality.
Let me know whether you find them helpful.

Greetings,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
DC
Top achievements
Rank 1
answered on 19 Nov 2009, 10:07 AM
Hi Mira,
Thanks for the reply.

I have see the mentioned article earlier also but it does not describe as to how can I get the old value when I am in edit mode so that I can set old value in dropdown.
For example: I have a row with value of "Currency Field" as "USD". Now I edit this row. When I am in edit mode, I want my dropdown to be
  1. Enabled
  2. Populated with all available currencies"XYZ", "ABC", "USD", "INR", "EUR", "YEN".
  3. old value as selected value in dropdown "USD" in this case
last point is where I am stuck. I want the old value "USD" to be the selected value in the dropdown. In order to do so, I need to have "old value" so that I can set it to be the selected value. Please advice some server side API by which I can get the old value.

Thanks in advance for your efforts to resolve my issue.
0
Accepted
Mira
Telerik team
answered on 19 Nov 2009, 01:50 PM
Hello,

Please check out the following code and tell me whether it implements the desired by you functionality:
protected void rgGLAdjustments_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        GridEditManager editMan = editedItem.EditManager;
        GridDropDownListColumnEditor editor = editMan.GetColumnEditor("LocalCurrency") as GridDropDownListColumnEditor;
        editor.DataSource = this.GetDataTable;
        editor.DataValueField = "LocalCurrency";
        editor.DataTextField = "LocalCurrencyValue";
        editor.DataBind();
        editor.DropDownListControl.SelectedValue = DataBinder.Eval(e.Item.DataItem, "CurrencyField").ToString();
    }
}


Sincerely yours,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
DC
Top achievements
Rank 1
answered on 20 Nov 2009, 10:34 AM
Thanks for the prompt reply Mira. Your code did the trick. I was just wondering as to why "editedItem.SavedOldValues" method as provided by telerik server side API failed?


Sincere regards,
DC
0
Mira
Telerik team
answered on 25 Nov 2009, 02:59 PM
Hello DC,

The SavedOldValues property is to be used in the Update command event handler for getting the old value of the edited item - for example as in this scenario.
For your case I assume that the appropriate approach is what I suggested in my previous post.

Sincerely yours,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
DC
Top achievements
Rank 1
answered on 26 Nov 2009, 07:36 AM
Hi Mira,
Thanks for your valuable inputs on my problem.
As our software development keeps going ahead, I will keep on bothering you with my issues as my team is new to Telerik controls.
Can you please provide me with some kind of file or link where we can have documentation on use of telerik controls.
We are using Q3 beta 2009 controls.
Looking forward to your kind support.

Thanks and regards,
DC
0
Princy
Top achievements
Rank 2
answered on 26 Nov 2009, 09:06 AM
Hello DC,

Here's the link to the online documentation on Telerik RadControls for ASP.NET AJAX. Hope this provides you with insights on the various RadControls:
RadControls for ASP.NET AJAX - Introduction

Thanks
Princy.
Tags
Grid
Asked by
DC
Top achievements
Rank 1
Answers by
Mira
Telerik team
DC
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or