Hi,
I am trying to generated BoundColumns dynamically, i have read the documentation (http://www.telerik.com/help/aspnet-ajax/grid-using-columns.html) and the programmatic example (http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html), and drafted the following code, but nothing is getting rendered in the page, could you please help,
I debugged and found that the columns collection has the columns as the way I added them but they are not rendered in my page.
Please note I have checked in IE9 / FF16 and using IIS7.5 & net framework 4.0
Find below my code....
aspx,
<telerik:RadGrid ID="RadGridStores" runat="server" AutoGenerateColumns="False" EnableViewState="False" CellSpacing="0" GridLines="Both">
<ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
<Selecting AllowRowSelect="True" />
<ClientEvents OnGridCreated="RadGridStores_OnGridCreated"/>
</ClientSettings>
<MasterTableView BorderStyle="Double" EnableViewState="False">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
<FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>
aspx.cs
private void SetUpDynamicColumns(UserAppletSettings usrAppConfig, RadGrid grid)
{
if (usrAppConfig.ItemCount <= 0) { return; }
Telerik.Web.UI.GridBoundColumn gbCol = null;
List<UsersDisplayColumnPKL> _enItems = null;
try
{
_enItems = new List<UsersDisplayColumnPKL>(usrAppConfig.ItemByColumnOrder.Values);
_enItems.Sort((UsersDisplayColumnPKL l, UsersDisplayColumnPKL r) => l.ColumnOrder.CompareTo(r.ColumnOrder));
_enItems = _enItems.FindAll((UsersDisplayColumnPKL item) => item.ColumnVisible != 0 ||
(item.ColumnVisible == 0 && item.ColumnOrder >= 999 && item.ColumnHidden == 0));
for (int index = 0, length = _enItems.Count; index < length; index++)
{
gbCol = new Telerik.Web.UI.GridBoundColumn();
grid.MasterTableView.Columns.Add(gbCol);
gbCol.Visible = true;
gbCol.HeaderText = _enItems[index].ColumnHeader;
gbCol.DataField = _enItems[index].ColumnName;
gbCol.UniqueName = _enItems[index].ColumnName;
}
}
finally
{
if (!ReferenceEquals(_enItems, null))
{
_enItems.Clear();
_enItems = null;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
// Pre-condition section
if (IsPostBack) return;
if (IsCallback) return;
SetCurrentTab();
SetUpDynamicColumns(new UserAppletSettings(WebDataKeys.SCR_OFSS, UserAppletSettings.EAppletType.STOR, this.RadGridStores.MasterTableView),
this.RadGridStores);
}
Regards
Sanjib Harchowdhury
I am trying to generated BoundColumns dynamically, i have read the documentation (http://www.telerik.com/help/aspnet-ajax/grid-using-columns.html) and the programmatic example (http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html), and drafted the following code, but nothing is getting rendered in the page, could you please help,
I debugged and found that the columns collection has the columns as the way I added them but they are not rendered in my page.
Please note I have checked in IE9 / FF16 and using IIS7.5 & net framework 4.0
Find below my code....
aspx,
<telerik:RadGrid ID="RadGridStores" runat="server" AutoGenerateColumns="False" EnableViewState="False" CellSpacing="0" GridLines="Both">
<ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
<Selecting AllowRowSelect="True" />
<ClientEvents OnGridCreated="RadGridStores_OnGridCreated"/>
</ClientSettings>
<MasterTableView BorderStyle="Double" EnableViewState="False">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
<FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>
aspx.cs
private void SetUpDynamicColumns(UserAppletSettings usrAppConfig, RadGrid grid)
{
if (usrAppConfig.ItemCount <= 0) { return; }
Telerik.Web.UI.GridBoundColumn gbCol = null;
List<UsersDisplayColumnPKL> _enItems = null;
try
{
_enItems = new List<UsersDisplayColumnPKL>(usrAppConfig.ItemByColumnOrder.Values);
_enItems.Sort((UsersDisplayColumnPKL l, UsersDisplayColumnPKL r) => l.ColumnOrder.CompareTo(r.ColumnOrder));
_enItems = _enItems.FindAll((UsersDisplayColumnPKL item) => item.ColumnVisible != 0 ||
(item.ColumnVisible == 0 && item.ColumnOrder >= 999 && item.ColumnHidden == 0));
for (int index = 0, length = _enItems.Count; index < length; index++)
{
gbCol = new Telerik.Web.UI.GridBoundColumn();
grid.MasterTableView.Columns.Add(gbCol);
gbCol.Visible = true;
gbCol.HeaderText = _enItems[index].ColumnHeader;
gbCol.DataField = _enItems[index].ColumnName;
gbCol.UniqueName = _enItems[index].ColumnName;
}
}
finally
{
if (!ReferenceEquals(_enItems, null))
{
_enItems.Clear();
_enItems = null;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
// Pre-condition section
if (IsPostBack) return;
if (IsCallback) return;
SetCurrentTab();
SetUpDynamicColumns(new UserAppletSettings(WebDataKeys.SCR_OFSS, UserAppletSettings.EAppletType.STOR, this.RadGridStores.MasterTableView),
this.RadGridStores);
}
Regards
Sanjib Harchowdhury