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

Binding data to the Editor

1 Answer 117 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Badrinarayanan
Top achievements
Rank 1
Badrinarayanan asked on 01 Sep 2008, 01:44 PM
I have a rad editor within a radgrid (inline editing).  When i click edit button, the data is not getting bound to the rad editor.
Here are the steps what i followed:


<radG:RadGrid TabIndex="11" ID="RadgWelcome" Width="100%" Skin="Glassy" SkinsPath="~/App_Themes/"

EnableAJAX="True" AutoGenerateColumns="False" LoadingTemplateTransparency="20"

ItemStyle-Height="20px" AlternatingItemStyle-Height="20px" AllowMultiRowEdit="false"

AllowMultiRowSelection="true" OnNeedDataSource="RadgWelcome_NeedDataSource" OnInsertCommand="RadgWelcome_InsertCommand"

OnUpdateCommand="RadgWelcome_UpdateCommand" OnDeleteCommand="RadgWelcome_DeleteCommand"

OnItemDataBound="RadgWelcome_ItemDataBound" MasterTableView-RetrieveAllDataFields="true"

EnableOutsideScripts="true" EnableAJAXLoadingTemplate="false" runat="server" AllowSorting="true"

PageSize="10" AllowPaging="true">

<MasterTableView Width="100%" HorizontalAlign="NotSet" AutoGenerateColumns="false"

CssClass="master" CommandItemStyle-CssClass="masteritem" CommandItemDisplay="Top">

<PagerStyle Mode="NumericPages" CssClass="pager" />

<%

--Link Button to add a new Division--%>

<CommandItemTemplate>

<asp:LinkButton ID="lnkAddNew" runat="server" CommandName="InitInsert" Visible='<%# !RadgWelcome.MasterTableView.IsItemInserted %>'>

<img style="border:0px" alt="" src="RadControls/Grid/Skins/Glassy/AddRecord.gif" />

Add a New Message

</asp:LinkButton>

</CommandItemTemplate>

<Columns>

<%

--Description--%>

<radG:GridTemplateColumn HeaderText="Employee Benefit Center" SortExpression="description"

DataField="description" ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="Middle">

<ItemTemplate>

<%

--<asp:Label ID="lblDesc" runat="server" Text='<%# Eval("description") %>' />--%>

<asp:Literal ID="lblDesc" runat="server" Text='<%# Eval("description") %>' Mode="PassThrough" />

</ItemTemplate>

</radG:GridTemplateColumn>

<radG:GridTemplateColumn SortExpression="description" DataField="description" ItemStyle-HorizontalAlign="left"

ItemStyle-VerticalAlign="Middle">

<ItemTemplate>

<asp:ImageButton ID="lnkButton" runat="server" CommandName="Edit" AlternateText="Edit"

ImageUrl="~/images/edit_icon.gif" />

</ItemTemplate>

</radG:GridTemplateColumn>

<radG:GridTemplateColumn HeaderText="" ItemStyle-Width="60px" ItemStyle-HorizontalAlign="left"

ItemStyle-VerticalAlign="Middle">

<%

--Delete Button--%>

<ItemTemplate>

<asp:ImageButton ID="imgbtnDelete" runat="server" ImageUrl="images/delete_icon.gif"

CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete?');"

CommandArgument='<%# Eval("id") %>' ToolTip="Delete" />

</ItemTemplate>

</radG:GridTemplateColumn>

</Columns>

<EditFormSettings EditFormType="Template">

<FormTemplate>

<fieldset>

<%

--Description--%>

<label for="Directory" class="formlabel left">

<span class="reqfld">*</span>Message Text</label>

<asp:HiddenField ID="hdnDesc" runat="server" Value='<%#Bind("description") %>' />

<radE:RadEditor runat="server" ID="txtDesc" Height="400px" ShowSubmitCancelButtons="false"

ShowPreviewMode="false" ShowHtmlMode="false" StripAbsoluteImagesPaths="false">

<content>

</content>

</radE:RadEditor>

<%

--Insert,Update and Cancel Buttons--%>

<div class="btnpnl">

<asp:Button ID="btnUpdate" CssClass="btn" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'

ToolTip='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server"

CommandArgument='<%# Eval("id") %>' CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'

TabIndex="0"></asp:Button>&nbsp;

<asp:Button ID="btnCancel" Text="Cancel" CssClass="btn" runat="server" CausesValidation="False"

CommandName="Cancel" ToolTip="Cancel" TabIndex="0"></asp:Button>

</div>

</fieldset>

</FormTemplate>

</EditFormSettings>

</MasterTableView>

</radG:RadGrid>


CODE BEHIND:

protected

void RadgWelcome_ItemDataBound(object sender, GridItemEventArgs e)

{

    try

    {

        if (e.Item is GridEditFormItem && e.Item.IsDataBound && e.Item.IsInEditMode)

        {

                GridEditFormItem gridEditFormItem = (GridEditFormItem)e.Item;

                HiddenField hdnDesc = (HiddenField)gridEditFormItem.FindControl("hdnDesc");

                RadEditor txtDesc = (RadEditor)gridEditFormItem.FindControl("txtDesc");

                txtDesc.Text = hdnDesc.Value;

            }

}

catch (Exception ex)

{

    lblError.Text = ex.Message;

}

}

1 Answer, 1 is accepted

Sort by
0
Tervel
Telerik team
answered on 03 Sep 2008, 03:23 PM
Hello Badrinarayanan,

I see that you try to set the editor's content using its read-only Text property.
The Text property returns the editor's content not as HTML but as pure text (with HTML tags and formatting stripped).

Since you have wrapped this code in a try/catch block you are not able to notice the actual problem.

The correct editor property to use is Content. Please change your code and see how it goes:

txtDesc.Content = hdnDesc.Value;


Greetings,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
Badrinarayanan
Top achievements
Rank 1
Answers by
Tervel
Telerik team
Share this question
or