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

Bind Grid to Dataset with multiple Datatable problem....

6 Answers 210 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Asa'ad
Top achievements
Rank 1
Asa'ad asked on 13 Jun 2012, 11:49 AM
Hi all,

i have an sql stored procedure that result in multiple data sets....

i get the data using ado.net and fill them in dataset...

then i use the needdatasource ecevnt to bind my grid with dataset...

the result always that the grid is bounded only to the first datatable in this dataset!!!! and i am sure that this dataset has more than one datatable....

i need to display the results from all datatables in this dataset using one grid....

all datatables have the same structure of columns....

    protected void gvData_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            getData();
              
        }
  
  protected void getData() 
        {
            try 
            {
                                  DataSet ds ;
                                 //code to get data from database through classes.
                             if (ds != null ) {
                                               gvData.DataSource = ds
                    }
                    else { 
                    //show error while getting data, contact your system admin
                    }
                }
catch (Exception ex)
            {
                //handle exception code
            }
        }


is is feature supported in RadGrid?
and if yes, what is wrong with my code???

please help me very soon...

thanks

Asa'ad

6 Answers, 1 is accepted

Sort by
0
Asa'ad
Top achievements
Rank 1
answered on 14 Jun 2012, 08:52 AM
please help this very critical...
asa'ad
0
Elliott
Top achievements
Rank 2
answered on 14 Jun 2012, 05:17 PM
did you try to create another datatable, assign it to the 2nd (or 3rd) datatable and use that as datasource?

Dim ds AS DataSet
Dim dt AS DataTable
 
...
ds = GetData(param,param,)
dt=ds.Tables(1)
rdgGrid.DataSource=dt
0
Richard
Top achievements
Rank 1
answered on 14 Jun 2012, 09:31 PM
Asa'ad,

If you assign a DataSet that has multiple tables to the RadGrid's DataSource, it will always bind the first table, unless you specify which table you want to bind to using the RadGrid.DataMember Property.

Use the DataMember property to specify a member from a multimember data source to bind to the list control. For example, if you have a data source with more than one table specified in the DataSource property, use the DataMember property to specify which table to bind to a data listing control.

RadGrid1.DataMember = "myDataTable";
RadGrid1.DataSource = myDataSet;   

Hope this helps!
0
Asa'ad
Top achievements
Rank 1
answered on 17 Jun 2012, 06:48 AM
Hi again...

assign the data member property will not help...

i need to display all data from all data tables in the dataset...

for example, my dataset has table1 and table2, i need to display rows of these two datatables in the grid togther....

the two tables have the same structure so there will be no problem with the binding to the grid....

but the the grid always show data from the first table only....

please help...

thanks

asa'ad...
0
Accepted
Shinu
Top achievements
Rank 1
answered on 18 Jun 2012, 05:52 AM
Hi,

One suggestion is to Merge the DataTables.

C#:
DataSet dt = new DataSet();
dt.Tables[0].Merge(dt.Tables[1]);
RadGrid1.DataSource = dt;

Please take a look into the this help documentation.

Thanks,
Shinu.
0
Asa'ad
Top achievements
Rank 1
answered on 18 Jun 2012, 06:40 AM
thank u shinu for your suggestion...

i created a new data table and loop through the dataset tables and merge each one of them to this created datatable...

now all results are shown as expected :-)

many thanks

asa'ad...
Tags
Grid
Asked by
Asa'ad
Top achievements
Rank 1
Answers by
Asa'ad
Top achievements
Rank 1
Elliott
Top achievements
Rank 2
Richard
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or