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

radgrid duplicating columns

1 Answer 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gary Goodwin
Top achievements
Rank 1
Gary Goodwin asked on 26 Sep 2013, 07:26 PM
HI

   I have a master-detail rad grid - with data set. Autogenerate columns is off. It is autogenerating columns.
So now I have duplicate columns.

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

Setup();

}

protected void Setup()

{

DataTable oTableParent = new DataTable("Parent");

oTableParent.Columns.Add("PKey", Type.GetType("System.Int32"));

oTableParent.Columns.Add("Code", Type.GetType("System.String"));

oTableParent.Columns.Add("Description", Type.GetType("System.String"));

oTableParent.Rows.Add(1,"AAAAA","aaaaaaaaaaaaaaa");

oTableParent.Rows.Add(2,"BBBBB","bbbbbbbbbbbbbbb");

DataTable oTableChild = new DataTable("Child");

oTableChild.Columns.Add("ChildPKey", Type.GetType("System.Int32"));

oTableChild.Columns.Add("PKey", Type.GetType("System.Int32"));

oTableChild.Columns.Add("Code", Type.GetType("System.String"));

oTableChild.Columns.Add("Description", Type.GetType("System.String"));

oTableChild.Rows.Add(1,1, "AAAA-A", "aaaaaaaaaaaaaaa");

oTableChild.Rows.Add(2,1, "AAAA-B", "aaaaaaabbbbbbbb");

oTableChild.Rows.Add(3, 2, "BBBB-A", "bbbbbbbbaaaaaaa");

oTableChild.Rows.Add(4, 2, "BBBB-B", "bbbbbbbbbbbbbbb");

DataColumn[] oKeys = new DataColumn[1];

oKeys[0] = oTableParent.Columns[0];

oTableParent.PrimaryKey = oKeys;

DataSet oDS = new DataSet();

oDS.Tables.Add(oTableParent);

oDS.Tables.Add(oTableChild);

oDS.Relations.Add("Primary", oDS.Tables[0].Columns[0], oDS.Tables[1].Columns[1]);

RadGrid1.AutoGenerateColumns = false;

RadGrid1.DataSource = oDS;

RadGrid1.DataBind();

}


<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="181px" Width="1091px" AllowSorting="True" DataMember="Parent">

<ClientSettings>

<Selecting AllowRowSelect="True" />

</ClientSettings>

<MasterTableView HierarchyLoadMode="ServerBind" AutoGenerateColumns="True" DataKeyNames="PKey" DataMember="Parent">

<DetailTables>

<telerik:GridTableView runat="server" AutoGenerateColumns="True" AllowSorting="False" DataMember="Child">

<%-- <ParentTableRelation>

<telerik:GridRelationFields DetailKeyField="PKey" MasterKeyField="PKey" />

</ParentTableRelation>--%>

<ParentTableRelation>

<telerik:GridRelationFields DetailKeyField="PKey" MasterKeyField="PKey" />

</ParentTableRelation>

<Columns>

<telerik:GridBoundColumn FilterControlAltText="Filter ChildPKey column" UniqueName="ChildPKey" DataType="System.Int32" HeaderText="ChildPKey" ReadOnly="True">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn DataField="PKey" FilterControlAltText="Filter PKey column" HeaderText="PKey" UniqueName="PKeyChild" DataType="System.Int32">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn DataField="Code" FilterControlAltText="Filter Code column" HeaderText="Code" UniqueName="CodeChild">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn DataField="Description" FilterControlAltText="Filter Description column" HeaderText="Description" UniqueName="DescriptionChild">

</telerik:GridBoundColumn>

</Columns>

</telerik:GridTableView>

</DetailTables>

<Columns>

<telerik:GridBoundColumn DataField="PKey" FilterControlAltText="Filter PKey column" HeaderText="PKey" UniqueName="PKey" DataType="System.Int32">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn DataField="Code" FilterControlAltText="Filter Code column" HeaderText="Code" UniqueName="Code">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn DataField="Description" FilterControlAltText="Filter Description column" HeaderText="Description" UniqueName="Description">

</telerik:GridBoundColumn>

<telerik:GridCheckBoxColumn DataType="System.Boolean" FilterControlAltText="Filter column column" UniqueName="column">

</telerik:GridCheckBoxColumn>

</Columns>

</MasterTableView>

</telerik:RadGrid>

Gary

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 27 Sep 2013, 04:06 AM
HI Gary,

I see that you have set the AutoGenerateColumns="true" for the MasterTableView and GridTableView.Please set it to false.

ASPX:
<MasterTableView HierarchyLoadMode="ServerBind" AutoGenerateColumns="false" DataKeyNames="PKey" DataMember="Parent">
  <DetailTables>
       <telerik:GridTableView runat="server" AutoGenerateColumns="false" DataMember="Child">
           . . . . . .

Thanks,
Princy
Tags
Grid
Asked by
Gary Goodwin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or