Can't Extract Value From GridHTMLEditorColumn

4 posts, 0 answers
  1. Richard Weeks
    Richard Weeks avatar
    95 posts
    Member since:
    Oct 2009

    Posted 23 Apr 2012 Link to this post

    I've bumped up against an unexpected roadblock when trying to extract the entered HTML from a GridHTMLEditorColumn.

    Briefly, I have something like this:

    In the Grid:
    <telerik:GridHTMLEditorColumn
        DataField="Content"
        HeaderText="Content"
        UniqueName="Content"
        Visible="false">
    </telerik:GridHTMLEditorColumn>

    Extracting the value:
    var hashTable = new Hashtable();
     
    using (var ownerTableView = e.Item.OwnerTableView)
    {
        ownerTableView.ExtractValuesFromItem(hashTable, editedItem);
    }

    Then:
    if (hashTable.ContainsKey("Content"))
    {
        this.Content = hashTable["Content"].ToString();
    }

    Or:
    var tableCell = editedItem["Content"];
     
    if (tableCell != null)
    {
        var radEditor = tableCell.Controls[0] as RadEditor;
     
        if (radEditor != null)
        {
            // At this point, all I have is string.Empty for radEditor.Content
            this.Content = string.IsNullOrEmpty(radEditor.Content) ? string.Empty : radEditor.Content;
        }
    }

    Nothing works. I can get hold of all my other bound column values. But I can't for the life of me work out how to get the HTML content.

    Help!

    Richard

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Apr 2012 Link to this post

    Hello Richard,

    Here is the sample code that I tried to access the update values which worked as expected.
    C#:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
     if (e.CommandName == RadGrid.UpdateCommandName)
     {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        RadEditor radEditor = (RadEditor)editedItem["Content"].Controls[0];//accessing HTMLColumnEditor
        string value1 = radEditor.Text;
         //accessing the updated values using HashTable
        Hashtable newValues = new Hashtable();
        e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
       if (newValues.ContainsKey("Content"))
       {
          string value2 = newValues["Content"].ToString();
       }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Richard Weeks
    Richard Weeks avatar
    95 posts
    Member since:
    Oct 2009

    Posted 23 Apr 2012 Link to this post

    I can see my approach was correct. Using your code, I retrieve string.Empty for the first attempt and null at the second.

    I was mystified. To further test, I created a declarative only page using EntityDataSource. I was able to produce a grid that worked as expected.

    After further enabling / disabling of code blocks, I have now traced the issue to a method we have been using for a very long time to set repetitive aspects of the RadGrid (allowing our declarative code to remain clear and concise). This methods is called in the Page_Init page event and is as follows:
    public static void ApplyDefaultGridSettings(RadGrid radGrid)
    {
        radGrid.Skin = "Telerik";
        radGrid.GridLines = GridLines.None;
        radGrid.ShowFooter = false;
        radGrid.GroupingEnabled = false;
        radGrid.AutoGenerateColumns = false;
        radGrid.CssClass = "telerikGrid";
        radGrid.HeaderContextMenu.EnableAutoScroll = false;
        radGrid.MasterTableView.GridLines = GridLines.None;
        radGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
        radGrid.MasterTableView.CommandItemSettings.AddNewRecordText = @"Add New Record.";
        radGrid.MasterTableView.CommandItemSettings.RefreshText = string.Empty;
        radGrid.MasterTableView.NoMasterRecordsText = @"No records have been added or no records match your current filter criteria.";
        radGrid.MasterTableView.ShowHeadersWhenNoRecords = true;
        radGrid.MasterTableView.EditFormSettings.ColumnNumber = 2;
        radGrid.MasterTableView.EditFormSettings.FormTableItemStyle.Wrap = false;
        radGrid.MasterTableView.EditFormSettings.FormCaptionStyle.CssClass = "EditFormHeader";
        radGrid.MasterTableView.EditFormSettings.FormMainTableStyle.CellSpacing = 0;
        radGrid.MasterTableView.EditFormSettings.FormMainTableStyle.CellPadding = 3;
        radGrid.MasterTableView.EditFormSettings.FormMainTableStyle.Width = Unit.Percentage(100);
        radGrid.MasterTableView.EditFormSettings.FormTableStyle.GridLines = GridLines.Horizontal;
        radGrid.MasterTableView.EditFormSettings.FormTableStyle.CellSpacing = 0;
        radGrid.MasterTableView.EditFormSettings.FormTableStyle.CellPadding = 2;
        radGrid.MasterTableView.EditFormSettings.FormTableStyle.CssClass = "module";
        radGrid.MasterTableView.EditFormSettings.FormTableStyle.Height = Unit.Pixel(110);
        radGrid.MasterTableView.EditFormSettings.FormTableStyle.Width = Unit.Percentage(100);
        radGrid.MasterTableView.EditFormSettings.FormTableAlternatingItemStyle.Wrap = false;
        radGrid.MasterTableView.EditFormSettings.FormStyle.Width = Unit.Percentage(100);
        radGrid.MasterTableView.EditFormSettings.FormStyle.BackColor = ColorTranslator.FromHtml("#EEF2EA");
        radGrid.MasterTableView.EditFormSettings.EditColumn.UpdateText = @"Update Record";
        radGrid.MasterTableView.EditFormSettings.EditColumn.UniqueName = "EditCommandColumn1";
        radGrid.MasterTableView.EditFormSettings.EditColumn.ButtonType = GridButtonColumnType.ImageButton;
        radGrid.MasterTableView.EditFormSettings.FormTableButtonRowStyle.HorizontalAlign = HorizontalAlign.Right;
        radGrid.MasterTableView.EditFormSettings.FormTableButtonRowStyle.CssClass = "EditFormButtonRow";
        radGrid.MasterTableView.RowIndicatorColumn.HeaderStyle.Width = Unit.Pixel(20);
        radGrid.MasterTableView.ExpandCollapseColumn.HeaderStyle.Width = Unit.Pixel(20);
        radGrid.FilterMenu.EnableTheming = true;
        radGrid.FilterMenu.CollapseAnimation.Duration = 200;
        radGrid.FilterMenu.CollapseAnimation.Type = AnimationType.OutQuint;
    }

    If I pass my RadGrid to this method, attempts to retrieve the HTMLEditor content will fail no matter what I try. If I remove the call, everything works (but I will have to manually set all of the above declaratively = yuck).

    Are you able to see why the code above would introduce this behaviour?

    Richard
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Apr 2012 Link to this post

    Hi Richard Weeks,

    I tried the same scenario but I couldn't replicate the issue. Can you please provide your complete code for further assistance.


    Thanks,
    Shinu.
Back to Top