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

NestedViewTemplate not rendering correctly

3 Answers 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 09 Sep 2011, 07:26 PM
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:

//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!

3 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 12 Sep 2011, 10:42 PM
I figured out my issue with the nested view template not displaying.  I was setting the HierarchyDefaultExpanded = false instead of true.  Now that that's fixed I still have the issue of when the template is rendered it adds a colgroup entry for the table set at 20px effectively messing up the table format.  Any help would be appreciated. Thanks!  
0
Galin
Telerik team
answered on 15 Sep 2011, 03:26 PM
Hello Chris,

I could not replicate the issue using your shared code. Can you please provide the event handlers and other databinding code as well. It would be even better if you could send a small running project that we can use to reproduce the case?

Generally, there should be no problem with adding a NestedViewTemplate this way, as you can see in this Code Library's project. You could use it as an example for how you should proceed:
Programmatic creation of RadGrid / Hierarchy with Templates

Greetings,
Galin
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
0
Chris
Top achievements
Rank 1
answered on 15 Sep 2011, 10:08 PM
I figured out the issue.  I had to hide the ExpandCollapseColumn.  Problem solved. 
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Galin
Telerik team
Share this question
or