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

AutoGenerateColumns Limitations/Issues

1 Answer 32 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 16 Jan 2014, 07:53 PM
Hi All,

I have an entirely code-behind solution that  uses AutoGenerateColumns = true.  I noticed two interesting issues:

1. Alternating rows lose their itemstyle formatting.  In this case I set RadGrid.ItemStyle.HorizontalAlign = HorizontalAlign.Center.  Only the rows without a back-color were centered.

2. There is a zero column count in ItemDataBound when accessing the RadGrid.  It is a private variable in the class.

Generating the columns manually (AutoGenerateColumns = false) does provide me with a column count and applies the ItemStyle to all rows which fixes my issue, but I would like to AutoGenerate the Columns.  Any thoughts?

Thanks,
Mark

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Jan 2014, 06:31 AM
Hi Mark,

I guess you are having AutoGenerated columns for your Grid. You can customize its properties in the OnColumnCreated event , and also make sure you set the style for both normal rows and Alternative rows as follows:

C#:
protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
    RadGrid1.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
    RadGrid1.AlternatingItemStyle.HorizontalAlign = HorizontalAlign.Center;
}

If you want to get the count of autogenerated columns use the PreRender event:
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    int count = RadGrid1.MasterTableView.AutoGeneratedColumns.Length;  
}

Thanks,
Shinu
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or