title: Getting the value of an edited item in a Telerik RadGrid
body: <p>ASPX:</p>
  
  <pre><code>&lt;telerik:RadGrid ID="ctlItemsGrid" runat="server" DataKeyNames="Id" AllowPaging="true" AllowSorting="true" GridLines="None" Skin="Windows7" EnableViewState="true"&gt;
      &lt;MasterTableView AutoGenerateColumns="false" AllowPaging="true" DataKeyNames="Id,WorkflowStatus" NoMasterRecordsText="No items exist in the database." EnableViewState="true"&gt;
          &lt;SortExpressions&gt;
              &lt;telerik:GridSortExpression FieldName="Id" SortOrder="Descending" /&gt;
          &lt;/SortExpressions&gt;
          &lt;PagerStyle Mode="NextPrevAndNumeric" /&gt;
          &lt;Columns&gt;            
              &lt;telerik:GridNumericColumn ColumnEditorID="ctlColumnId" HeaderText="ID" DataField="Id" DecimalDigits="0" DataType="System.Int32" NumericType="Number" ReadOnly="true"&gt;&lt;/telerik:GridNumericColumn&gt;
              &lt;telerik:GridDropDownColumn UniqueName="ctlColumnGridWorkflow" ColumnEditorID="ctlColumnWorkflow" HeaderText="Workflow" DataField="WorkflowStatus" DropDownControlType="DropDownList"&gt;&lt;/telerik:GridDropDownColumn&gt;
              &lt;telerik:GridEditCommandColumn UniqueName="ctlColumnGridEdit" CancelText="Cancel" EditText="Edit"&gt;&lt;/telerik:GridEditCommandColumn&gt;
              &lt;telerik:GridButtonColumn UniqueName="ctlColumnGridDelete" CommandName="Delete" CommandArgument="" Text="Remove"&gt;&lt;/telerik:GridButtonColumn&gt;
          &lt;/Columns&gt;
      &lt;/MasterTableView&gt;
  &lt;/telerik:RadGrid&gt;
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>public partial class administration_modules_item_Default : ViewPageBase&lt;IItemAdminPresenter, IItemAdminView&gt;, IItemAdminView
  {
      private IEnumerable&lt;WorkflowStatus&gt; _workflowStatuses;
      private IEnumerable&lt;IItemDbItem&gt; _items;
  
      protected override void PreloadView()
      {
          this.ctlItemsGrid.ItemDataBound += new Telerik.Web.UI.GridItemEventHandler(ctlItemsGrid_ItemDataBound);
          this.ctlItemsGrid.ItemCommand += new GridCommandEventHandler(ctlItemsGrid_ItemCommand);
          //this.ctlItemsGrid.ItemUpdated += new GridUpdatedEventHandler(ctlItemsGrid_ItemUpdated);
          this.ctlItemsGrid.UpdateCommand += new GridCommandEventHandler(ctlItemsGrid_UpdateCommand);
      }
  
      protected override void PostLoadView()
      {
          // Doesn't work, values are all empty strings
          //foreach (GridEditableItem editItem in ctlItemsGrid.EditItems)
          //{
          //    Dictionary&lt;string, string&gt; newValues = new Dictionary&lt;string, string&gt;();
          //    ctlItemsGrid.MasterTableView.ExtractValuesFromItem(newValues, editItem);
          //    IItemDbItem w = (IItemDbItem)editItem.DataItem;
          //    if (!string.IsNullOrWhiteSpace(newValues["WorkflowStatus"]))
          //    {
          //        w.WorkflowStatus = (WorkflowStatus)Enum.Parse(typeof(WorkflowStatus), newValues["WorkflowStatus"]);
          //        this.Presenter.Update(w.Id, w.WorkflowStatus);
          //    }
          //}
  
          ctlItemsGrid.DataSource = _items;
          ctlItemsGrid.DataBind();
  
          base.PostLoadView();
      }
  
      void ctlItemsGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
      {
          if (e.Item is GridEditableItem &amp;&amp; (e.Item as GridEditableItem).IsInEditMode)
          {
              GridEditableItem editedItem = e.Item as GridEditableItem;
              GridEditManager editMan = editedItem.EditManager;
              IItemDbItem w = (IItemDbItem)e.Item.DataItem;
  
              // This doesn't work either, values are all null or empty:
              //if (editedItem.CanExtractValues)
              //{
              //    Dictionary&lt;string, string&gt; newValues = new Dictionary&lt;string,string&gt;();
              //    editedItem.ExtractValues(newValues);
              //    if (newValues["WorkflowStatus"] != null)
              //    {
              //        w.WorkflowStatus = (WorkflowStatus)Enum.Parse(typeof(WorkflowStatus), newValues["WorkflowStatus"]);
              //        this.Presenter.Update(w.Id, w.WorkflowStatus);
              //    }
              //}
  
              GridDropDownListColumnEditor ctlColumnWorkflow = editMan.GetColumnEditor("ctlColumnGridWorkflow") as GridDropDownListColumnEditor;
              ctlColumnWorkflow.DataSource = _workflowStatuses;
              ctlColumnWorkflow.DataBind();
              ctlColumnWorkflow.SelectedValue = w.WorkflowStatus.ToString();
  
          }
          else if (e.Item is GridDataItem)
          {
              GridDataItem dataItem = e.Item as GridDataItem;
  
              IItemDbItem w = (IItemDbItem)e.Item.DataItem;
  
              dataItem["ctlColumnGridWorkflow"].Text = w.WorkflowStatus.ToString();
          }
      }
  
      void ctlItemsGrid_ItemCommand(object sender, GridCommandEventArgs e)
      {
          string cmdName = e.CommandName;
          IItemDbItem w = (IItemDbItem)e.Item.DataItem;
  
          switch (cmdName)
          {
              case "Delete":
                  this.Presenter.Delete(w.Id);
                  this.Presenter.LoadView();
                  break;
              case "Update":
                  // This doesn't work either: 
                  //GridEditableItem editedItem = e.Item as GridEditableItem;
                  //GridEditManager editMan = editedItem.EditManager;
                  //DropDownList editWorkflow = (DropDownList)editedItem["ctlColumnGridWorkflow"].Controls[0];
                  //DropDownList editEvent = (DropDownList)editedItem["ctlColumnGridEvent"].Controls[0];
                  //this.Presenter.Update(w.Id, (WorkflowStatus)Enum.Parse(typeof(WorkflowStatus));
                  break;
          }
  
          //this.Presenter.LoadView();
      }
  
      // Doesn't work: 
      //void ctlItemsGrid_ItemUpdated(object sender, GridUpdatedEventArgs e)
      //{
      //    GridEditableItem editedItem = e.Item as GridEditableItem;
      //    GridEditManager editMan = editedItem.EditManager;
      //    DropDownList editWorkflow = editedItem["ctlColumnGridWorkflow"].Controls[0] as DropDownList;
      //    IItemDbItem w = (IItemDbItem)e.Item.DataItem;
      //    this.Presenter.Update(w.Id, (WorkflowStatus)Enum.Parse(typeof(WorkflowStatus), editWorkflow.SelectedValue));
      //}
  
      // Doesn't work: 
      void ctlItemsGrid_UpdateCommand(object sender, GridCommandEventArgs e)
      {
          GridEditableItem editedItem = e.Item as GridEditableItem;
          GridEditManager editMan = editedItem.EditManager;
          DropDownList editWorkflow = editedItem["ctlColumnGridWorkflow"].Controls[0] as DropDownList;
          IItemDbItem w = (IItemDbItem)e.Item.DataItem;
  
          this.Presenter.Update(w.Id, (WorkflowStatus)Enum.Parse(typeof(WorkflowStatus), editWorkflow.SelectedValue));
      }
  
      public IEnumerable&lt;WorkflowStatus&gt; WorkflowStatuses
      {
          set
          {
              _workflowStatuses = value;
          }
      }
  
      public IEnumerable&lt;IItemDbItem&gt; Items
      {
          get
          {
              return _items;
          }
          set
          {
              _items = value;
          }
      }
  
  }
  </code></pre>
  
  <p>I have a separate form to add items (not shown), that works fine. Also the Delete button works fine. When trying to update the saved item, all the values that I can get from the GridDropDownColumn are either null, empty, or the default values, not the edited values. When stepping through and testing things in the Immediate Window in Visual Studio, I was able to find the correct value using this ridiculous statement: </p>
  
  <pre><code>((DropDownList)ctlItemsGrid.MasterTableView.GetItems(GridItemType.EditFormItem)[0].Controls[1].Controls[0].Controls[0].Controls[1].Controls[0].Controls[0].Controls[1].Controls[1].Controls[0]).SelectedValue
  </code></pre>
  
  <p>But there has to be an easier way. What am I doing wrong?</p>