DataBind for templates

5 posts, 0 answers
  1. Warnestam
    Warnestam avatar
    83 posts
    Member since:
    Sep 2006

    Posted 08 Aug 2008 Link to this post

    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
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 11 Aug 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Warnestam
    Warnestam avatar
    83 posts
    Member since:
    Sep 2006

    Posted 12 Aug 2008 Link to this post

    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
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 13 Aug 2008 Link to this post

    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.
  6. Warnestam
    Warnestam avatar
    83 posts
    Member since:
    Sep 2006

    Posted 13 Aug 2008 Link to this post

    Vlad,

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

    Thanks for your help!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017