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

[Solved] Retreiving Edited Value From Popup Window

4 Answers 192 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 01 Jul 2009, 12:13 PM
I have a simple RadGrid bound to a business object. When I Add or Edit with the Automatic PopUp, I can not get the new / updated value from the PopUp window.

The Grid is setup with the following:
        <telerik:RadGrid ID="LocationGrid" runat="server" Skin="Web20" OnDeleteCommand="OnLocationDelete" 
            OnInsertCommand="OnLocationInsert" OnItemDeleted="OnLocationItemDeleted" OnItemInserted="OnLocationItemInserted" 
            OnItemUpdated="OnLocationItemUpdated" OnNeedDataSource="OnNeedDataSource"  
            OnUpdateCommand="OnLocationUpdate" ShowStatusBar="True"  
            AutoGenerateColumns="False" GridLines="None" onitemcommand="OnItemCommand"
            <PagerStyle Mode="NextPrevAndNumeric" /> 
            <MasterTableView EditMode="PopUp" CommandItemDisplay="Top"
                <Columns> 
                    <telerik:GridBoundColumn DataField="ID" UniqueName="colID" Visible="false" DataType="System.Int32"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Description" UniqueName="colDescription" HeaderText="Description"
                    </telerik:GridBoundColumn> 
                    <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="colDelete" HeaderText="Delete"
                    </telerik:GridButtonColumn> 
                    <telerik:GridButtonColumn CommandName="Edit" Text="Edit" UniqueName="colEdit" HeaderText="Edit"
                    </telerik:GridButtonColumn> 
                </Columns> 
                <EditFormSettings CaptionFormatString="Edit Location" /> 
            </MasterTableView> 
        </telerik:RadGrid> 
 

I am binding to a simple business object with the following code:
        private List<Location> LocationList  
        { 
            get 
            { 
                return Session["LocationList"as List<Location>; 
            } 
            set 
            { 
                Session["LocationList"] = value; 
            } 
        } 
 
        private void BuildInitialList() 
        { 
            LocationList = new List<Location> 
                { 
                    new Location() {ID = 1, Description = "Some Location"}, 
                    new Location() {ID = 2, Description = "Some Other Location"}, 
                }; 
        } 
 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack) 
                BuildInitialList(); 
            LocationGrid.DataSource = LocationList; 
            LocationGrid.DataBind(); 
        } 
 

When I click on Edit for one of the values, I am able to change the existing value for the description, but both methods for retrieving the new value in the code below return the old value:
protected void OnLocationUpdate(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    GridEditableItem item = e.Item as GridEditableItem; 
     
    // Description is the old value 
    string Description = (item["colDescription"].Controls[0] as TextBox).Text; 
 
    // values["Description"] is the old value 
    Dictionary<stringstring> values = new Dictionary<stringstring>(); 
    item.ExtractValues(values); 
 

Any ideas?






4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Jul 2009, 01:24 PM
Hello Richard,

Please check out the following points and let me know of any further  issues.

1) Try casting the items as GridEditFormItem to use the ExtractValuesFromItem method:
protected void OnLocationUpdate(object source, Telerik.Web.UI.GridCommandEventArgs e)  
{  
    GridEditFormItem item = e.Item as GridEditFormItem;  
      
    // Description is the old value  
    string Description = (item["colDescription"].Controls[0] as TextBox).Text;  
  
    // values["Description"] is the old value  
    Dictionary<stringstring> values = new Dictionary<stringstring>();  
    item.ExtractValues(values);  
}  

2) Make sure that you have enabled the ViewState of your grid.

Thanks,
Princy
0
Richard
Top achievements
Rank 1
answered on 01 Jul 2009, 01:38 PM
Hi Princy,

Thanks for the quick response. Unfortunately I get the same issue.

Both

string Description = (item["colDescription"].Controls[0] as TextBox).Text;

and

values["Description"]

return the old value.





0
Princy
Top achievements
Rank 2
answered on 02 Jul 2009, 12:37 PM
Hello Richard,

If you want to perform manual Update operation and not automatic update operation, then you would have to remove all automatic operation settings from the grid. For instance set AllowAutomaticUpdates to false. Automatic operations will work only if the grid is bound to a DataSourceControl.  In all other situations you should perform updates manually.

Thanks
Princy.
0
Akber Ali
Top achievements
Rank 1
answered on 29 Oct 2009, 04:10 AM
hello
I did every thing i.e. automaticupdates are false, but still extract values returns old values. There must be a bug at least. All the colums are boud type and I am using INPlace editing.
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Richard
Top achievements
Rank 1
Akber Ali
Top achievements
Rank 1
Share this question
or