Click here to Skip to main content
15,794,593 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting 6 table into my dataset with each table having different different columns that means my first table in dataset has 4 columns second table in dataset has 6 columns third table has 10 columns in this way all the six tables in dataset has different columns i need to bind all those tables to a single gridview in a treeview structure that is first table in dataset with + and - to expand and collapse ,second table in dataset with + and - to expand and collapse,third table in dataset with + and - to expand and collapse,fourth table in dataset with + and - to expand and collapse for all the six tables but i am able to bind only first table in dataset to gridview
private void BindGrid()
           DataSet ds = new DataSet();
           DataTable dt = new DataTable();
           GridView gvEmployee = new GridView();
           gvEmployee.AutoGenerateColumns = false;
           if (ds != null && ds.HasChanges())
               dt = ds.Tables[0];
               for (int i = 0; i < dt.Columns.Count; i++)
                   BoundField boundfield = new BoundField();
                   boundfield.DataField = dt.Columns[i].ColumnName.ToString();
                   boundfield.HeaderText = dt.Columns[i].ColumnName.ToString();
               gvEmployee.DataSource = dt;
               gvEmployee.Width = 600;
               gvEmployee.HeaderStyle.CssClass = "header";
               gvEmployee.RowStyle.CssClass = "rowstyle";

above is my code which creates 6 tables in dataset but only one table is getting binded to gridview at the end but i need to bind all those tables to a gridview with expand and collapse for each table in dataset

What I have tried:

i need to bind all the tables in dataset to a single gridview that means i have 6 tables in my dataset those 6 tables have different different columns all these tables should be binded to single gridview with expand and collapse for those six tables which we are getting in dataset
Updated 25-May-17 1:23am

1 solution

It is not possible to bind same gridview with multiple tables.

For this purpose, DataRepeater is best idea.

<asp:Repeater ID="Repeater1" runat="server">
             Your Header
        <asp:GridView runat="server" ID="grd" AutoGenerateColumns="false">
                //Your GridView Attributes

Use Bootstrap Accodion for Collapse and expand in ItemTemplate and put the Grid in Accordion.

In Repeater data bound event, find the grid control using FindControl method and bind the data to grid view.

GridView grid = e.Item.FindControl("grd") as GridView;
grid.DataSource = dataTable;
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900