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;
}
}
}
}
}