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

Not able to get New Value on UpdateCommand

1 Answer 192 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 21 Feb 2011, 04:08 PM
Hi, I am new to using Telerik controls, I thought that using the controls would shorten my work, but so far doing one simple task is actually making it longer for me to complete what I am working on.  I have tried every possible way to get this to work, and searched just about every thread and have not found an answer that works. I am trying to get the new value on a field that has been updated by the user.  Each method I have tried only returns the old value.  I have tried placing the values in a Hashtable using the ExtractValues method, I have tried getting the value using the GridTextColumnEditor, etc.  Every example on here I have tried.  Please help.  I am using an instance of a LINQ datacontext, or more particular. I use a method that submits a query using an instance of a LINQ datacontext, the method returns the data as a Generic List, and I use this to set the datasource for the Grid. As shown in the code-behind below.  The data shows, sorts, pages, filters perfectly, but when I try to edit or update I start to get issues.  In my code behind, you will see that I tried both recommend ways and neither has worked for me.

Thanks in Advance

Markup Code:

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" PageSize="10" AllowSorting="true" ShowGroupPanel="true" AutoGenerateColumns="False"
    AllowMultiRowSelection="true" CellPadding="0" AllowMultiRowEdit="true" OnNeedDataSource="RadGrid1_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand" AllowAutomaticUpdates="true">
    <MasterTableView DataKeyNames="Spot_IDX" GroupLoadMode="Client" EditMode="InPlace" CommandItemDisplay="Top" AllowAutomaticUpdates="true">
     <CommandItemTemplate>
        <telerik:RadToolbar ID="RadToolBar1" OnButtonClick="RadToolBar1_ButtonClick" runat="server">
            <Items>
                <telerik:RadToolBarButton Text="Edit" CommandName="EditAll" ImageUrl="~/App_Themes/Default/Images/Telerik/Edit.gif" Visible='<%# RadGrid1.EditIndexes.Count == 0 %>' runat="server"></telerik:RadToolBarButton>
                <telerik:RadToolBarButton Text="Update" CommandName="UpdateEdited" ImageUrl="~/App_Themes/Default/Images/Telerik/Update.gif" Visible='<%# RadGrid1.EditIndexes.Count > 0 %>'></telerik:RadToolBarButton>
                <telerik:RadToolBarButton Text="Cancel Editing" CommandName="CancelAll" ImageUrl="~/App_Themes/Default/Images/Telerik/Cancel.gif" Visible='<%# RadGrid1.EditIndexes.Count > 0%>'></telerik:RadToolBarButton>
                <telerik:RadToolBarButton Text="Refresh Spot List" CommandName="RebindGrid" ImageUrl="~/App_Themes/Default/Images/Telerik/Refresh.gif"></telerik:RadToolBarButton>
                 
  
            </Items>
              
  
                 
        </telerik:RadToolbar>
          
     </CommandItemTemplate>
    <Columns>
         <telerik:GridClientSelectColumn UniqueName="TagCheckboxSelectColumn" HeaderText="Tag" HeaderStyle-Width="45"/>
  
<telerik:GridBoundColumn UniqueName="House ID"
                        SortExpression="HouseID" HeaderText="House ID" DataField="HouseID" HeaderStyle-Width="190" ColumnEditorID="1">
         </telerik:GridBoundColumn>
  
 </Columns>
      
    </MasterTableView>
    <ClientSettings AllowDragToGroup="true" AllowGroupExpandCollapse="true" DataBinding-EnableCaching="true" AllowColumnsReorder="true" >
    <Selecting AllowRowSelect="true"/>
    <Scrolling UseStaticHeaders="True" AllowScroll="true"/>
    <Resizing AllowResizeToFit="true"  AllowColumnResize="true"/>       
    <ClientEvents OnRowDblClick="RowDblClick" />
  
    </ClientSettings>
      
    </telerik:RadGrid>

Code-Behind (C#)
Public partial class Inbox : System.Web.UI.Page 
SpotDataAccess spotAccess = new SpotDataAccess();
        protected void Page_Load(object sender, EventArgs e)
        {
              RadGrid1.DataSource = spotAccess.ReturnAllSpots();
             RadGrid1.DataBind();
        }
  
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
        {
                      Hashtable newValues = new Hashtable();
               ((GridEditableItem)e.Item).ExtractValues(newValues); 
                          
                   GridEditableItem editedItem = e.Item as GridEditableItem;
                GridEditManager editMan = editedItem.EditManager;
  
                foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
                {
                    if (column is IGridEditableColumn)
                    {
                        IGridEditableColumn editableCol = (column as IGridEditableColumn);
                        if (editableCol.IsEditable)
                        {
                            IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
  
                            string editorType = editor.ToString();
                            string editorText = "unknown";
                            object editorValue = null;
  
                            if (editor is GridTextColumnEditor)
                            {
                                editorText = (editor as GridTextColumnEditor).Text;
                                editorValue = (editor as GridTextColumnEditor).Text;
                            }
                        }
                    }
                }
         }
  
         protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            this.RadGrid1.DataSource = spotAccess.ReturnAllSpots();
        }

1 Answer, 1 is accepted

Sort by
0
Greg
Top achievements
Rank 1
answered on 21 Feb 2011, 05:15 PM
I have gotten this to work now.  Turns out  I forgot to remove or set the Automatic Update condition to "False" and it now works.  Duh! :)
Tags
Grid
Asked by
Greg
Top achievements
Rank 1
Answers by
Greg
Top achievements
Rank 1
Share this question
or