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

Custom column templates

1 Answer 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gilberto
Top achievements
Rank 1
Gilberto asked on 10 Jul 2009, 02:48 PM
I am implementing some custom columns templates,  Consulting the samples when i use a "Textbox" as a editor control everything works fine, but if a change to a RadCombo or RadEditor as a main grideditor, i get one error in databinding event, even to insert.

I am a little confusing about container's, data item, editmode etc.

Someone to help plz.

Thanks

 public class ComboItemEditTemplate : ITemplate
    {

        protected RadComboBox comboBox;
        private string columnName;
        protected Field campo;
        protected String errorMessage = string.Empty;
        String connectionString;
        public ComboItemEditTemplate(string ColumnName, string ErrorMessage, Field _Campo, String _connectionString)
        {
            columnName = ColumnName;
            errorMessage = ErrorMessage;
            campo = _Campo;
            connectionString = _connectionString;
        }
        public void InstantiateIn(System.Web.UI.Control container)
        {
            comboBox = new RadComboBox();
            comboBox.ID = String.Format("RadCombo{0}", columnName);
            comboBox.DataBinding += new EventHandler(comboBox_DataBinding);
            comboBox.DataBind();
            comboBox.DataTextField = campo.Description.GetElementsByTagName("DataTextField")[0].InnerText;
            comboBox.DataValueField = campo.relation.PkKey;
            container.Controls.Add(comboBox);

        }

        public void comboBox_DataBinding(object sender, EventArgs e)
        {
            RadComboBox combo = (RadComboBox)sender;

            Helper helper = new Helper();

            combo.DataSource = helper.RetornaDatasetCombo(campo, connectionString);


            // GridDropDownColumnEditor container = (GridDropDownColumnEditor)combo.NamingContainer;
            //  combo.SelectedValue = ((DataRowView)container.DataItem)[columnName].ToString();
        }
    }

Gilberto

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 15 Jul 2009, 01:29 PM
Hello Gilberto,

How to build grid template columns programmatically you can see from the following help article in the RadGrid documentation:

http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html (see the bottom section of the topic)

In case you use RadComboBox as editor, bind the control to data and receive error on initial insert, consider setting its AppendDataBoundItems property to true and set an empty item in the control or provide predefined value on init insert as explained here (see paragraph 3).

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Gilberto
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or