dnnGrid does not show Column Headers for Programmatically created Columns
Description
QA Test Plan
Activity
William SeveranceJanuary 31, 2013 at 7:35 PM
I don't believe that this is a bug but rather a design decision. The DnnGrid automatically localizes the header text from the parent control's LocalResourceFile using what you have specified as a column's HeaderText with ".Header" appended as its localization key. For example if you supply "Name" as a column's HeaderText, you will also need to add "Name.Header" and its localized value to the parent control's local resource file.
When you have AutoGenerateColumns set to true, the underlying RadGrid builds its columns during databinding after DNN localization of the column header text has occurred allowing the field names to properly display.
It would be good for the DnnGrid to implement a property to disable automatic localization of column header text when the developer does not wish to localize their module control.
William SeveranceJanuary 31, 2013 at 7:35 PM
I don't believe that this is a bug but rather a design decision. The DnnGrid automatically localizes the header text from the parent control's LocalResourceFile using what you have specified as a column's HeaderText with ".Header" appended as its localization key. For example if you supply "Name" as a column's HeaderText, you will also need to add "Name.Header" and its localized value to the parent control's local resource file.
When you have AutoGenerateColumns set to true, the underlying RadGrid builds its columns during databinding after DNN localization of the column header text has occurred allowing the field names to properly display.
It would be good for the DnnGrid to implement a property to disable automatic localization of column header text when the developer does not wish to localize their module control.
Brief Description of Issue:
dnnGrid works fine with automatically generated columns. But when I tried to add columns to dnnGrid programmatically (from DataTable) - Grid is created, but Column Headers are missing
Clear Steps to Reproduce:
1. Create ASCX page with the following controls (placeholders):
<%@ Control language="C#" Inherits="Fobos.Modules.TestPage" CodeFile="TestPage.ascx.cs" AutoEventWireup="true"%>
<h2>Example 1. dnnGrid - Auto Generated Columns</h2>
<asplaceHolder ID="phlAutoGrid" runat="server"></asplaceHolder>
<br />
<h2>Example 2. dnnGrid - Programmatically created Columns</h2>
<asplaceHolder ID="phlProGrid" runat="server"></asplaceHolder>
2. Create CS page with Code (any data source could be used):
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;
using DotNetNuke.Web.UI.WebControls;
namespace Fobos.Modules
{
/// ----------------------------------------------------------------------------- /// <summary>
/// The ViewFobos class displays the content
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// </history>
/// ----------------------------------------------------------------------------- partial class TestPage : PortalModuleBase
{
protected void Page_Load(System.Object sender, System.EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
// populate Grid with Automatically generated columns
MakeAutoGeneratedGrid();
// populate Grid with Programmatically created Columns
MakeGridByProgram();
}
else
{
}
}
catch (Exception exc) //Module failed to load
{
//Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected void MakeAutoGeneratedGrid()
{
// define new Grid & add to page placeholder
DnnGrid grdTest = new DnnGrid();
phlAutoGrid.Controls.Add(grdTest);
// Set Grid Properties
grdTest.AllowPaging = true;
grdTest.AllowSorting = true;
grdTest.AutoGenerateColumns = true;
grdTest.ShowHeader = true;
// Data Binding
grdTest.DataSource = GetDataTable();
grdTest.DataBind();
}
protected void MakeGridByProgram()
{
// define new Grid & add to page placeholder
DnnGrid grdProTest = new DnnGrid();
phlProGrid.Controls.Add(grdProTest);
// Set Grid Properties
grdProTest.AllowPaging = true;
grdProTest.AllowSorting = true;
grdProTest.AutoGenerateColumns = false;
grdProTest.ShowHeader = true;
// Data Source
DataTable MyDataTable=GetDataTable();
grdProTest.DataSource = MyDataTable;
// Add Bound Columns to Grid
DnnGridBoundColumn MyGridColumn;
// Loop in DataSource Columns
foreach (DataColumn MySourceColumn in MyDataTable.Columns)
{
MyGridColumn = new DnnGridBoundColumn();
grdProTest.MasterTableView.Columns.Add(MyGridColumn);
MyGridColumn.DataField = MySourceColumn.ColumnName;
MyGridColumn.DataType = MySourceColumn.DataType;
MyGridColumn.HeaderText = MySourceColumn.ColumnName;
}
// Data Binding
grdProTest.Rebind(); // grdProTest.DataBind() - could be used too, no changes in result
}//MakeGridByProgram
public DataTable GetDataTable()
{
// Get Connection String to test Database ("VendorDB")
String strConnectionString = ConfigurationManager.ConnectionStrings["VendorDB"].ToString();
String strSQL = "Select * FROM dbo.US_ZIP";
// Get Data Table
DataTable dtZip = SqlHelper.ExecuteDataset(strConnectionString, CommandType.Text, strSQL).Tables[0];
return(dtZip);
}
}
}
Actual Result:
1. Two grid created, but second one (with programmatically created columns) does not have Column Headers.
Expected Result:
Grids must be identical