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

[Solved] Find a radeditor inside a EditItemTemplate

2 Answers 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SonicImaging
Top achievements
Rank 1
SonicImaging asked on 22 Apr 2008, 05:10 PM
Hi,  im having trouble finding my radeditor inside a EditItemTemplate.  I get the Object reference not set to an instance of an object.  I am trying to change the ViewPaths inside the imagemanager during Item.  Am I missing something?

   protected void RG1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem item = e.Item as GridEditableItem; 
 
            RadEditor theEditor = item["mainContent"].Controls[0] as RadEditor; 
            theEditor.ImageManager.ViewPaths[0] = "~/SIsites/ClientFiles/ClientUploads/Images/"
            theEditor.ImageManager.UploadPaths[0] = "~/SIsites/ClientFiles/ClientUploads/Images/"
            theEditor.ImageManager.DeletePaths[0] = "~/SIsites/ClientFiles/ClientUploads/Images/"
        } 
 
 
    } 


<telerik:GridTemplateColumn DataField="mainContent" HeaderText="Main Content" SortExpression="mainContent" 
                    UniqueName="mainContent" Display="false"
                    <EditItemTemplate> 
                        <telerik:RadEditor ID="RE1" runat="server" Content='<%# Bind("mainContent") %>' ToolsFile="~/SIadmin/editors/ToolsFile.xml" 
                            Height="200px" Width="600px" Skin="Telerik"
                        </telerik:RadEditor> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 

2 Answers, 1 is accepted

Sort by
0
SonicImaging
Top achievements
Rank 1
answered on 22 Apr 2008, 10:02 PM
I figured it out and ended up doing it on the ItemDataBound.

It works great but is this the best pace to set Editor attributes at runtime in the ItemDataBound? 


protected void RG1_ItemDataBound(object sender, GridItemEventArgs e)  
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem item = e.Item as GridEditableItem; 
 
            // RE1 = the radeditor in the EditItemTemplate 
            RadEditor theEditor = item.FindControl("RE1"as RadEditor; 
            string[] imagepath = { "~/images/" }; 
            theEditor.ImageManager.ViewPaths = imagepath; 
            theEditor.ImageManager.UploadPaths = imagepath; 
            theEditor.ImageManager.DeletePaths = imagepath; 
        } 
    }  



0
Sebastian
Telerik team
answered on 23 Apr 2008, 07:03 AM
Hi Keith,

The best place to set dynamically RadEditor properties when the control is used inside edit template of template column is the ItemCreated event (since it is raised on each postback request while ItemDataBound is fired when the grid is bound to data):

http://www.telerik.com/help/radcontrols/prometheus/?grdEventSequence.html

The main differences between the ItemCreated/ItemDataBound events are outlined here.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
SonicImaging
Top achievements
Rank 1
Answers by
SonicImaging
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or