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

Programmatic Creation of Template Columns and EditItemIndexes

1 Answer 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 18 Mar 2009, 06:54 PM
I have followed the steps in the following article to create a template column programmatically:

http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html

However, it doesn't seem to address how to make it work if you allow edits. I set the EditItemIndex like this:

RadGridCoverages.EditIndexes.Add(RadGridCoverages.Items.Count - 1)  
 
 

But it has no effect since in the template column the Enabled property of the checkbox is being set to false. How do I detect if the checkbox should be enabled or not in my custom template class so that setting the EditItemIndexes actually works?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 23 Mar 2009, 12:22 PM
Hi Joe,

If you have correctly created your template column, the EditItemInexes collection should work as expected. When you are creating a template column that should allow editing, you need to assign a new object of your custom class to the EditItemTemplate property of the template column and in the DataBinding event for the controls in the column take into consideration that their naming container will be of type GridEditFormItem.

For example, if the column in the help article you have cited should allow editing, then you need the following line of code in the Page_Init event:

templateColumn.EditItemTemplate = new MyTemplate(templateColumnName); 

Then, the handler for the data binding event of the literal controls becomes:

    public void lControl_DataBinding(object sender, EventArgs e)  
    {  
        LiteralControl l = (LiteralControl)sender;  
        GridDataItem container = l.NamingContainer as GridDataItem;  
 
        if (container != null)  
            l.Text = ((DataRowView)container.DataItem)[colname].ToString() + "<br />";  
        else 
        {  
            GridEditFormItem editFormContainer = l.NamingContainer as GridEditFormItem;  
 
            if (editFormContainer != null)  
                l.Text = ((DataRowView)editFormContainer.DataItem)[colname].ToString() + "<br />";  
        }  
 
    } 

Hope this helps.

Best Regards,
Tsvetoslav
the Telerik team

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