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

Template Columns DataBinding not hooking up

1 Answer 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
CANUSA
Top achievements
Rank 1
CANUSA asked on 02 Jul 2012, 10:38 PM
I have a grid with a number of columns. The data seems to be coming back fine from my datasource, as I have an accurate row count when paging is enabled. However, all columns are blank. When I view source, I see the markup generated by the InstantiateIn, but no data. It seems either the DataBinding event handler is not hooked up OR the grid is being defined (along with the event handlers) AFTER the data comes back and binds. I have followed the demos to the "T" and can't seem to get this to work. This is all embedded in a SharePoint visual web part. Thanks for any ideas/tips/solutions.

public class Name : ITemplate
{
    #region ITemplate Members
 
    public void InstantiateIn(Control container)
    {
        // open main container
        container.Controls.Add(new LiteralControl("<div class=\"related-rm-eb-results-gridview-name\">"));
 
        using (var nameLiteral = new Literal())
        {
            nameLiteral.ID = "Name";
            nameLiteral.DataBinding += NameDataBinding;
            container.Controls.Add(nameLiteral);
        }
 
        // close main container
        container.Controls.Add(new LiteralControl("</div>"));
    }
 
    #endregion
 
    public void NameDataBinding(object sender, EventArgs e)
    {
        using (var nameLiteral = sender as Literal)
        {
            if (nameLiteral != null)
            {
                var item = nameLiteral.NamingContainer as GridDataItem;
                if (item != null)
                {
                    var entity = item.DataItem as DataContracts.Entity;
                    if (entity != null)
                        nameLiteral.Text = entity.Name;
                }
            }
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 05 Jul 2012, 07:54 AM
Hi,

 Have you tried using the NeedDataSource event to bind the grid and also check whether the NameDataBinding event handler gets executed? It will be helpful if you can share code which shows how exactly you define and bind the grid in the webpart.

Regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
CANUSA
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or