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

radgrid is auto incrementing column headers

3 Answers 140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 04 Apr 2012, 05:19 AM
When there are multiple column headers with the same name, the radgrid keeps adding a number to the end of the header. For example if I have repeating column headers that are aa, bb, cc, aa, bb, cc, aa, bb, cc the radgrid displayes them as aa, bb, cc, aa1, bb1, cc1, aa2, bb2, cc2 and so on. Is there a way to turn this off.
This is my code:
  <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource3" Skin="Simple"
                CellSpacing="0" GridLines="None" Font-Size="8pt" CellPadding="0"  Wrap="False">
                <MasterTableView DataSourceID="SqlDataSource3" CommandItemDisplay="Top" Font-Size="8" CellPadding="0" Wrap="False">
                    <ItemStyle Wrap="False" />
                    <CommandItemTemplate>
                        <%=gridHeader%>
                    </CommandItemTemplate>
                    <CommandItemSettings ShowExportToWordButton="true" ShowExportToExcelButton="true"
                        ShowExportToCsvButton="true" />
                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>
                    <EditFormSettings>
                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                        </EditColumn>
                    </EditFormSettings>
                </MasterTableView>
                <HeaderStyle Font-Size="8pt" Font-Underline="False" Wrap="False" />
                <FilterMenu EnableImageSprites="False">
                </FilterMenu>
                <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                </HeaderContextMenu>
            </telerik:RadGrid>



 Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 05 Apr 2012, 10:51 PM
Hi Chris,

I suppose that you are using auto-generated columns in your project. If so, note that this behaviour is expected, since the datasource have to declare a different field name to each property in order to be able to distinguish the columns when needed. Consequently, the unique name of each column gets  its  value from the relevant DataField and finally the header text generates from that unique name.

Thus, in order to solve your problem, you will have to either:
  • create your columns declaratively and define your preferred HeaderText in the column tags
  • access the columns in the code-behind and trim their HeaderText as showed below:
protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
    {
        GridColumn col = e.Column;
        col.HeaderText = col.HeaderText.TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' });
    }

Furthermore, can you tell us why you need to use same DataField in your project and what you want to achieve, so we can  advice you a proper solution.

Hope this helps. Good luck with your project.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Chris
Top achievements
Rank 1
answered on 06 Apr 2012, 05:28 AM
I added this code in the code behind but I could not get it to work. I am creating an app with multiple cross tabs, columns, and two headers.The top headers are generated from a CommandItemTemplate and the bottom headers are the columns from the data. This is a image of the app http://img834.imageshack.us/img834/1433/telerik2.jpg In the image the top headers are the age ranges and the sub headers are the primary turnouts for every age range.  The primary turnout headers need to be the same for every age range, that is why I need column headers to be the same. There are multiple different combination's of headers so I don't think declaring the text is an option. Do you have any ideas why this is not working in my case? Or is there a better way to do this?
Thanks for your help
0
Eyup
Telerik team
answered on 10 Apr 2012, 02:37 PM
Hi Chris,

As I explained in my previous post, this issue is related to your DataSource and in your scenario automatic modification of  the headers is not  possible. You need to customize them explicitly.
For your convenience I have attached a RadGrid page sample where I implemented a scenario resembling yours.
Please give it a look and see where our projects differ because on my side this approach works properly.

If the problem remains please open a support ticket and send us runnable version of your application which demonstrates the problematic beahvior. Thus we will be able to further research on the problem and do our best to provide a proper solution.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Chris
Top achievements
Rank 1
Share this question
or