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

Dynamic Columns

3 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Samantha
Top achievements
Rank 1
Samantha asked on 16 May 2008, 01:56 AM
I am currently reviewing the a trial of the ASP.NET AJAX 2008 controls.  I'm having a problem with columns being automatically generated when the autogeneratecolumns is set to false.  I have a DataTable that I have "pivoted" with a function.  My RadView's datasource is set to this DataTable (in the NeedDataSource event).  I need the columns of the RadView to be in a specific order so I have put code like the following in the Page_Load event:

if

(!IsPostBack)
{
//Important: first Add column to the collection, Then set properties
GridBoundColumn boundCol = new GridBoundColumn();
this.RadGrid1.MasterTableView.Columns.Add(boundCol);
boundCol.DataField =
"CompanyName";
boundCol.HeaderText =
"Company";
}

etc.

This new bound column gets added just fine, however, all of the other columns from the DataTable are added as well. 

I've also noticed, that the code I have in my "ColumnCreated" event does not seem to fire on the columns I add dynamically.  I have a switch statement that checks the header text to decide what the background color should be set to.  This code works just fine on the other columns.

Any ideas what is causing this behavior?  Also, if I'm going to long way about either one of these two issues (Setting a specific column order, and conditionally applying a column background color) please let me know.  Thank you!

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 May 2008, 04:49 AM
Hi Samantha,

Sending your aspx will be more good. You can also refer the following help document link.
Programmatic creation

Shinu.
0
Samantha
Top achievements
Rank 1
answered on 16 May 2008, 10:26 AM

Sure, here it is:

<
telerik:RadGrid ID="RadGrid1" runat="server"

            OnNeedDataSource="RadGrid1_NeedDataSource"

            OnColumnCreated="RadGrid1_ColumnCreated"

            OnItemCreated="RadGrid1_ItemCreated" Skin="WebBlue"

            BorderColor="Black" BorderStyle="Solid"

            BorderWidth="1px" OnItemDataBound="RadGrid1_ItemDataBound"

            GridLines="None" OnDataBound="RadGrid1_DataBound"

            AutoGenerateColumns="False" AllowPaging="True"

            OnItemCommand="RadGrid1_ItemCommand">

           

            <MasterTableView AutoGenerateColumns="True">

                <RowIndicatorColumn Visible="False">

                    <HeaderStyle Width="20px" />

                </RowIndicatorColumn>

                <ExpandCollapseColumn Resizable="False" Visible="False">

                    <HeaderStyle Width="20px" />

                </ExpandCollapseColumn>

                <EditFormSettings>

                    <PopUpSettings ScrollBars="None" />

                </EditFormSettings>

                <PagerTemplate>

                    <asp:LinkButton ID="date22" runat="server" CommandName="7/22/2008"

                        Text="7/22/2008" ></asp:LinkButton>

                    <asp:LinkButton ID="date23" runat="server" CommandName="7/23/2008"

                        Text="7/23/2008"></asp:LinkButton>

                    <asp:LinkButton ID="date24" runat="server" CommandName="7/24/2008"

                        Text="7/24/2008"></asp:LinkButton>

                </PagerTemplate>

            </MasterTableView>

            <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" AllowColumnHide="True">

                <ClientEvents OnGridCreated="GetGridObject"></ClientEvents>

            </ClientSettings>

            <PagerStyle Position="Top" AlwaysVisible="True" />

        </telerik:RadGrid>

 

0
Samantha
Top achievements
Rank 1
answered on 16 May 2008, 08:18 PM
I see my error now, thanks!
Tags
Grid
Asked by
Samantha
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Samantha
Top achievements
Rank 1
Share this question
or