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

EditItemTemplate + IBindableTemplate + ExtractValues OnUpdateCommand = "Editor cannot be initialized for column: <columnName>"

1 Answer 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 05 May 2011, 10:18 AM
Hello.
I am creating a servercontrol that inherits the radgrid.
I am creating it on "OnLoad"
I want to create a GridDropDownColumn that will be filled by a DataSet.
From what i read i saw i have 3 options :
1) GridDropDownColumn with DataSourceID  ,
 2) DropDownColumn that can "bind" to the gridDataSource ( the gridatasource must have both id and text - and i can only have the id) 
3) Template.
I can't use number 1 and 2. so the only option is template.
I created a class for ItemTemplate, and one for EditItemTemplate.
The problem i have is with the EditItemTemplate

   class DropDownListTemplate : IBindableTemplate<br>
    {<br>
        string dataField = null;<br>
        bool enabled;<br>
        DropDownList ddl = null;<br>
<br>
        public DropDownListTemplate(string dataField, bool enabled)<br>
        {<br>
            this.dataField = dataField;<br>
            this.enabled = enabled;<br>
        }<br>
<br>
        void ITemplate.InstantiateIn(Control container)<br>
        {<br>
            ddl = new DropDownList();<br>
            ddl.Enabled = enabled;<br>
            ddl.DataBinding += ddl_DataBinding;<br>
            container.Controls.Add(ddl);<br>
        }<br>
<br>
        void ddl_DataBinding(object sender, EventArgs e)<br>
        {<br>
            ddl = (DropDownList)sender;<br>
            ddl.ID = dataField;<br>
            GridEditFormItem bidingContainer = ddl.NamingContainer as GridEditFormItem;<br>
            string value =  ((DataRowView)bidingContainer.DataItem)[dataField].ToString();<br>
<br>
            ddl.Items.Add(value);<br>
<br>
        }<br>
  <br>
<br>
        IOrderedDictionary IBindableTemplate.ExtractValues(Control container)<br>
        {<br>
            OrderedDictionary dick = new OrderedDictionary();<br>
            dick.Add(dataField, ddl.SelectedValue.ToString());<br>
            return dick;<br>
        }<br>
    }




I wanted to make it only ITemplate but i got an error saying i need to make it IBindableTemplate.

On ItemDataBound i find the template, get the dropdownlist and bind it to my DataSet.
When i push the "Edit" command it works. The problem appears when i push "Update".

On the "GridTelerik_UpdateCommand" event i need to Extract the new values.
But i get an error at : ((GridEditableItem)e.Item).ExtractValues(newValues);

The error is : "Editor cannot be initialized for column :  <columnName> - where columnName is the uniqueName of the TemplateColumn.

Is there a way i can resolve it. Does it have a problem because i instantiate the column editItemTemplate on Load? In case there is a better solution for this situation please advice me.
Thanks.

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 11 May 2011, 08:01 AM
Hello George,

When creating a grid dynamically that contains a template column it must be added in the Page_Init event so that the template controls can be added to the ViewState. More information you could find on the following link:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html (Creating template columns programmatically section)

Please give it try and let me know if you experience any problems.

Regards,
Radoslav
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
George
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or