Accessing Readonly/Hidden Fields in Edit Mode (RadGrid)

4 posts, 0 answers
  1. MK
    MK avatar
    29 posts
    Member since:
    Jul 2010

    Posted 17 Sep 2012 Link to this post

    I checked following link:

    http://www.telerik.com/community/forums/aspnet-ajax/grid/accessing-readonly-hidden-fields-in-edit-mode-radgrid.aspx#2292669 

    but when i used given code then i got following error-

     protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
        { 
            GridEditFormItem Data = (GridEditFormItem)e.Item;  
            string strHiddenField=Data.ParentItem["ProductName"].Text; 
            Hashtable ht = new Hashtable(); 
            Data.ExtractValues(ht); 
            ht.Add("ProductName", strHiddenField); 
        } 


    Unable to cast object of type 'Telerik.Web.UI.GridDataItem' to type 'Telerik.Web.UI.GridEditFormItem'

    Any solve it? 
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Sep 2012 Link to this post

    Hi,

    I guess you are using 'InPlace' edit mode for the RadGrid. Please try using 'GridEditableItem' instead of 'GridEditFormItem'.

    C#:
    protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
    {
          GridEditableItem Data = (GridEditableItem)e.Item; 
          string strHiddenField=Data.ParentItem["ProductName"].Text;
          Hashtable ht = new Hashtable();
          Data.ExtractValues(ht);
          ht.Add("ProductName", strHiddenField);
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. MK
    MK avatar
    29 posts
    Member since:
    Jul 2010

    Posted 17 Sep 2012 Link to this post

    Yes i am using "InPlace" Edit mode.

    I tried given code but i got a following error-

    'Telerik.Web.UI.GridEditableItem' does not contain a definition for 'ParentItem' and no extension method 'ParentItem' accepting a first argument of type 'Telerik.Web.UI.GridEditableItem' could be found (are you missing a using directive or an assembly reference?)

  5. Casey
    Casey avatar
    299 posts
    Member since:
    Jul 2009

    Posted 17 Sep 2012 Link to this post

    Hi MK,

    While debugging the UpdateCommand event were you able to verify that e.Item is in fact a GridEditFormItem? If not, I'm guessing that using InPlace for the edit mode causes e.Item to be a GridDataItem. If that is the case, then you should be able to get your column's value by casting e.Item as a GridDataItem and referencing the hidden column that way.

    I hope this helps!
    Casey

    protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
    {
          //Breakpoint here to determine what e.Item really is
          GridDataItem Data = (GridDataItem)e.Item;
          string strHiddenField=Data["ProductName"].Text;
          Hashtable ht = new Hashtable();
          Data.ExtractValues(ht);
          ht.Add("ProductName", strHiddenField);
    }
Back to Top