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

Auto generated Nested grids

3 Answers 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 18 Sep 2014, 05:10 PM
I am quite lost with this.
I have a radgrid that has auto generated columns. The user selects an item from a drop down list and the grid load the selected table.
The tables have all the same DB structure: Id-Code-Description-Bla....Bla-Sub.
If the filed "Sub" contains the value "yes" means that the Code has is own table and is not a  single item. So there are rows representing single items and rows  representing another table.

<telerik:RadGrid ID="RadGrid1" runat="server" Culture="it-IT" AllowPaging="True" AllowSorting="True" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True">
                <ExportSettings ExportOnlyData="True">
                    <Pdf PageWidth="">
                    </Pdf>
                </ExportSettings>
                <ClientSettings>
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                </ClientSettings>
                <MasterTableView CommandItemDisplay="Top" DataKeyNames="Code" InsertItemPageIndexAction="ShowItemOnCurrentPage">
                    <CommandItemSettings ShowExportToExcelButton="True" />
                    <Columns>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton">
                            <HeaderStyle Width="30px" />
                        </telerik:GridEditCommandColumn>
                        <telerik:GridButtonColumn ButtonType="ImageButton" Text="Delete" CommandName="Delete" FilterControlAltText="Filter column1 column" ConfirmDialogType="RadWindow" ConfirmText="Do you really want to delete this project and all its content?" UniqueName="Cancel">
                            <HeaderStyle Width="30px" />
                        </telerik:GridButtonColumn>
                    </Columns>
 
                    <EditFormSettings>
                        <EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
                    </EditFormSettings>
                    <PagerStyle AlwaysVisible="True" />
                </MasterTableView>
                <PagerStyle AlwaysVisible="True" />
            </telerik:RadGrid>

How can I auto generate the nested grid if the filed value of "Sub" in any row  is "yes"?
Thanks for supporting,
Felice

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 23 Sep 2014, 04:33 PM
Hello Felice,

The following code library demonstrates RadGrid's capability to auto-generate a hierarchical representation of a mutli-table DataSet. Just set the AutogenerateHierarchy property of RadGrid to true and it will automatically generate the hierarchy based on the tables in the DataSet and their relations with one another:
http://www.telerik.com/support/code-library/autogenerated-hierarchy

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Felice
Top achievements
Rank 1
answered on 27 Sep 2014, 09:37 AM
Hello Pavlina,
thanks for your support and for pointing me to a sample project. Unfortunately the sample does not seems to help me. I have a different situation:
The user selects a "bill of material" from a dropdown (it is an sql table):
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList1.DataSource = SqlDataSource2;
            DropDownList1.DataBind();
        }
        SetDataSource();
    }
 
    protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex > 0)
        {
            SetDataSource();
            RadGrid1.Rebind();
            
        }
    }
 
    private void SetDataSource()
    {
        if (DropDownList1.SelectedIndex > 0)
        {
            string tableInUse = DropDownList1.SelectedItem.Text;
            RadGrid1.DataSource = SqlDataSource1;
            SqlDataSource1.DeleteCommand = "DELETE FROM [" + tableInUse + "] WHERE [Id] = @Id";
            SqlDataSource1.InsertCommand = "INSERT INTO [" + tableInUse + "] ([Code], [Description], [Bkgroup], [Stgroup], [Quantity], [BomNote], [UnitEng], [AlternCost]) VALUES (@Code, @Description, @Bkgroup, @Stgroup, @Quantity, @BomNote, @UnitEng, @AlternCost)";
            SqlDataSource1.SelectCommand = "SELECT prod.Id, prod.Code, prod.Description, prod.Bkgroup, prod.Stgroup, prod.Quantity," +
                                           "prod.BomNote, prod.UnitEng, prod.AlternCost, comp.Unit, comp.Cost, comp.NoteComp " +
                                           "FROM  " + tableInUse + " prod " +
                                           "left JOIN  Components comp ON  comp.Code = prod.Code order by code";
            SqlDataSource1.UpdateCommand = "UPDATE [" + tableInUse + "] SET [Code] = @Code, [Description] = @Description, [Bkgroup] = @Bkgroup, [Stgroup] = @Stgroup, [Quantity] = @Quantity, [BomNote] = @BomNote, [UnitEng] = @UnitEng, [AlternCost] = @AlternCost WHERE [Id] = @Id";
        }
    }

Once the selection is made, the data gets loaded into the RadGrid. Up to this point it is all fine and working.
Now, the problem I am facing is that most of the rows represent a single record but some of them have instead the own database table with a list of records. I can differentiate the records which have the own table from the single row records adding a field "Sub" with a value "yes" or "not"  and for those particular records I need to create the nested table. The sql tables are all the same: 
[Id] [int] IDENTITY(1,1) NOT NULL,
[Code] [float] NULL,
[Description] [nvarchar](max) NULL,
[Bkgroup] [float] NULL,
[Stgroup] [float] NULL,
[Quantity] [float] NULL,
[BomNote] [nvarchar](max) NULL,
[UnitEng] [nvarchar](50) NULL,
[AlternCost] [float] NULL,
[Sub] [nvarchar](50) NULL,

The point where I am lost is: how can I add the nested grid, pointing to a specific table only for those records that contain a value yes or not in the field "Sub". Attached you will find a pic representing the above situation.
I am completely lost on this and working alone I am not coming right. Your support will be really appreciated.

Kind regards,
Felice


0
Pavlina
Telerik team
answered on 02 Oct 2014, 08:42 AM
Hello,

You can try using the DetailItemTemplate provided by RadGrid and see if you will be able to achieve the requested appearance:
http://demos.telerik.com/aspnet-ajax/grid/examples/columns-rows/rows/detailitemtemplate/defaultcs.aspx

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Felice
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Felice
Top achievements
Rank 1
Share this question
or