RadEditor for ASP.NET AJAX

RadControls for ASP.NET AJAX

You can use RadEditor in a EditItemTemplate of a DataGrid, taking advantage of the standard framework provided by the DataGrid control. The example below demonstrates:

 

Configure the Web Application for RadEditor

In a new AJAX Enabled Web Application:

Add Data File

  1. Locate the Access database file "email.mdb" in the \<RadControls for ASP.NET AJAX installation folder>\Live Demos\App_Data.

  2. In the Solution Explorer, copy the "email.mdb" file to the project's App_Data folder.

Configure Controls in Designer

  1. Add the DataGrid, RadEditor and label controls to your page. You can paste the ASP markup shown below.

    Note

    The key portion of markup to notice in the example below is the tag EditItemTemplate that contains the RadEditor. You can bind text from the database to the editor by assigning the Content property with an Eval statement:

    Content='<%# Eval("Body") %>'

    Note that this is done as an attribute of the <telerik:RadEditor> tag and not within the <Content> child element. Also note that the Eval statement is surrounded in single quotes.

    CopyASPX
    <asp:DataGrid ID="MyDataGrid" runat="server" OnUpdateCommand="MyDataGrid_Update"
        OnEditCommand="MyDataGrid_Edit" AutoGenerateColumns="False" OnCancelCommand="MyDataGrid_CancelCommand">
        <Columns>
            <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" />
            <asp:TemplateColumn Visible="False">
                <ItemTemplate>
                    <asp:Label ID="lblID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ID") %>' />
                </ItemTemplate>
            </asp:TemplateColumn>
            <asp:BoundColumn DataField="name" HeaderText="Name" ReadOnly="True" />
            <asp:BoundColumn DataField="date" HeaderText="Date" ReadOnly="True" />
            <asp:TemplateColumn HeaderText="Email Subject">
                <ItemTemplate>
                    <asp:Label ID="lblField1" CssClass="text" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Subject") %>' />
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadEditor ID="RadEditor1" runat="server" Content='<%# Eval("Body") %>' EditModes="Design"
                        Skin="Vista" Width="300px" Height="200px">
                        <Tools>
                            <telerik:EditorToolGroup>
                                <telerik:EditorTool Name="Cut" />
                                <telerik:EditorTool Name="Copy" />
                                <telerik:EditorTool Name="Paste" />
                            </telerik:EditorToolGroup>
                        </Tools>
                        <Modules>
                            <telerik:EditorModule Name="RadEditorStatistics" ScriptFile="" />
                        </Modules>
                    </telerik:RadEditor>
                </EditItemTemplate>
            </asp:TemplateColumn>
        </Columns>
    </asp:DataGrid>

Handle Events in Code-Behind

  1. Add the namespaces System.Data.OleDb and Telerik.Web.UI to your "uses" (C#) or "Imports" (VB) portion of the code-behind.

  2. In the code-behind, create helper methods to connect to the Email table and populate the grid:

  3. Create event handlers for the grid Update, Edit and Cancel events. Also handle the Page_Load event to initially populate the grid. Replace the event handler code with the example below:

See Also