I have created a series of RadGrids dynamically from a SQL Datasource. The grid is a list of reports with information pertaining to each report (format, frequency, published date). I need to add a NestedViewTemplate to each row so that I can also display the report description.
All this worked fine when declaring the RadGrid in the .ascx and then binding in code behind. Using those grids as templates I removed the declarations, inserted a placeholder and started creating the grids dynamically. That also worked fine. It only goes haywire when i try to add a NestedViewTemplate. Basically what happens is that though there are 4 columns defined for the list, it renders a 5th with no content and causes the defined columns to shift left by one. Can anyone tell me what I'm doing wrong? Here's the code:
And the Template Class:
Thanks!
All this worked fine when declaring the RadGrid in the .ascx and then binding in code behind. Using those grids as templates I removed the declarations, inserted a placeholder and started creating the grids dynamically. That also worked fine. It only goes haywire when i try to add a NestedViewTemplate. Basically what happens is that though there are 4 columns defined for the list, it renders a 5th with no content and causes the defined columns to shift left by one. Can anyone tell me what I'm doing wrong? Here's the code:
//Create Grid object
var rgReport =
new
Telerik.Web.UI.RadGrid
{
CssClass = css,
Width = Unit.Percentage(100),
PageSize = 5,
AllowPaging =
true
,
AllowSorting =
true
,
AutoGenerateColumns =
false
,
DataSource = dataSource,
ID = itemName
};
//Nested template
rgReport.MasterTableView.NestedViewTemplate =
new
EeisNestedTemplate();
rgReport.MasterTableView.NestedViewSettings.DataSourceID =
"Description"
;
// ReportName column
GridHyperLinkColumn reportName =
new
GridHyperLinkColumn
{
DataTextField =
"ReportName"
,
HeaderText =
"Report Name"
,
};
var landingURL =
new
string
[1];
landingURL[0] =
"LandingPageUrl"
;
reportName.DataNavigateUrlFields = landingURL;
reportName.DataNavigateUrlFormatString =
"{0}"
;
reportName.HeaderStyle.Width = Unit.Pixel(340);
reportName.HeaderStyle.Wrap =
true
;
// Report Format
GridBoundColumn reportFormat =
new
GridBoundColumn
{
HeaderText =
"Format"
,
DataField =
"Format"
};
reportFormat.HeaderStyle.Width = Unit.Pixel(66);
reportFormat.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
// Report Frequency
GridBoundColumn reportFrequency =
new
GridBoundColumn
{
HeaderText =
"Frequency"
,
DataField =
"Frequency"
};
reportFrequency.HeaderStyle.Width = Unit.Pixel(80);
// Report Publish Date
GridBoundColumn reportPublishedDate =
new
GridBoundColumn
{
HeaderText =
"Published"
,
DataField =
"Published"
,
DataFormatString =
"{0:MM/dd/yyyy}"
};
reportPublishedDate.HeaderStyle.Width = Unit.Pixel(70);
//Pager Template
rgReport.MasterTableView.PagerTemplate =
new
EeisPagerTemplate { itemCount = dataSource.Count };
rgReport.MasterTableView.PagerStyle.AlwaysVisible =
true
;
rgReport.MasterTableView.PagerStyle.Mode = GridPagerMode.NumericPages;
rgReport.MasterTableView.PagerStyle.PageButtonCount = 3;
//Misc Properties
rgReport.MasterTableView.ID =
"MasterView"
+ reportCategoryCount.ToString();
rgReport.MasterTableView.HierarchyDefaultExpanded =
false
;
//Add columns
rgReport.MasterTableView.Columns.Add(reportName);
rgReport.MasterTableView.Columns.Add(reportFormat);
rgReport.MasterTableView.Columns.Add(reportFrequency);
rgReport.MasterTableView.Columns.Add(reportPublishedDate);
return
rgReport;
And the Template Class:
internal
class
EeisNestedTemplate : ITemplate
{
protected
Literal nestedContent;
protected
Panel headerObj;
public
string
description {
get
;
set
; }
public
void
InstantiateIn(System.Web.UI.Control container)
{
headerObj =
new
Panel();
headerObj.ID =
"panel"
+ Guid.NewGuid().ToString();
nestedContent =
new
Literal();
nestedContent.ID =
"literal"
+ Guid.NewGuid().ToString();
nestedContent.Text =
"Report Description"
;
headerObj.Controls.Add(nestedContent);
container.Controls.Add(headerObj);
}
}
Thanks!