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

DataBind for templates

4 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Warnestam
Top achievements
Rank 1
Warnestam asked on 08 Aug 2008, 08:14 AM
Hi,

I'm creating a RadGrid on the Page_Init phase. It cotains both temlate columns and ordinary ones. I have problems with one of the template columns.

Here is the code that instantiates the templates (creating a button and a placeholder):
public void InstantiateIn(System.Web.UI.Control container)  
        {  
            // Info  
            ImageButton lbInfo = new ImageButton();  
            lbInfo.ImageUrl = Resources.UrlImages.Table_Info;  
            lbInfo.CommandName = COMMAND_INFO;  
            lbInfo.AlternateText = Resources.Glossary.Information;  
            lbInfo.DataBinding += new EventHandler(this.Info_DataBinding);  
            lbInfo.ID = "lbInfo";  
            container.Controls.Add(lbInfo);  
                      
            // Status  
            PlaceHolder phStatusHolder = new PlaceHolder();  
            phStatusHolder.DataBinding += new EventHandler(this.StatusHolder_DataBinding);  
            phStatusHolder.ID = "phHolder";  
            container.Controls.Add(phStatusHolder);  
 
            Literal lit = new Literal();   
            lit.Text = "ONLY TEST, THIS LABEL IS ALWAYS VISIBLE";  
            phStatusHolder.Controls.Add(lit);  
        } 
This works fine, my button is always visible.  The problem is that the StatusHolder_DataBinding is adding some images based on the data. This images are visible the first time, but disappears during postbacks (like clicking the button in the template).

Thanks for any help

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Aug 2008, 07:09 AM
Hi Warnestam,

You should add controls in InstantiateIn method. DataBinding event will be called only when the grid is bound and if the grid child controls are recreated from ViewState there will be no DataBinding call. Other possible solution is to data-bind the grid on every page lifecycle however in this case you will loose the ViewState.

Sincerely yours,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Warnestam
Top achievements
Rank 1
answered on 12 Aug 2008, 06:16 PM
Thanks for your help.

We have recently converted from Microsoft to telerik RadGrid. Somehow Microsoft saved the dynamicly controls created in the template. But in this case I have to rebind the control, even if there is a lot of overhead.

/Robert
0
Vlad
Telerik team
answered on 13 Aug 2008, 05:13 AM
Hello Warnestam,

The behavior is the same in standard Microsoft GridView and DataGrid controls.

All the best,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Warnestam
Top achievements
Rank 1
answered on 13 Aug 2008, 05:57 AM
Vlad,

My mistake, I checked it out and there where a forced databind after every action to the page.

Thanks for your help!
Tags
Grid
Asked by
Warnestam
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Warnestam
Top achievements
Rank 1
Share this question
or