how can bind two tables to one grid view
-
hello Can anybody tell me how to bind morethan two tables to grid view I want to add items from one table and can add year and month value from another tables
-
hello Can anybody tell me how to bind morethan two tables to grid view I want to add items from one table and can add year and month value from another tables
Are you talking about tables in a database or tables in a DataSet? In the database you can join the tables together use SQL to produce a single result set.
Man who stand on hill with mouth open wait long time for roast duck to drop in
-
hello Can anybody tell me how to bind morethan two tables to grid view I want to add items from one table and can add year and month value from another tables
First of all the question itself is not clear. Case I Assuming that it is database table Solution Produce a single resultset by aplying join or any other condition based on your demand Case II Assuming it is DataTable Solution Create a custom datatable table that will have all the fields. Fill the table programatically and then make it as the datasource of your grid view e.g. [ Some rough pseudo code]
Datatable dt1 = new Datatable();
dt1.Columns.Add(Col1);
dt1.Columns.Add(Col2);dt1.Rows.Add("Val1","Val2");
dt1.Rows.Add("Val3","Val4");Datatable dt2 = new Datatable();
dt2.Columns.Add(Year);
dt2.Columns.Add(Month);dt2.Rows.Add("2001","Jan");
dt2.Rows.Add("2002","Feb");Datatable dtFinal = new Datatable();
dtFinal .Columns.Add(Col1);
dtFinal .Columns.Add(Col2);
dtFinal .Columns.Add(Year);
dtFinal .Columns.Add(Month);
dtFinal .Rows.Add("Val1","Val2","2001","Jan");
dtFinal .Rows.Add("Val3","Val4","2002","Feb");myDatagrid.DataSource = dtFinal;
myDatagrid.DataBind();Hope this helps :) vote please
Niladri Biswas
modified on Saturday, June 13, 2009 11:07 AM
-
hello Can anybody tell me how to bind morethan two tables to grid view I want to add items from one table and can add year and month value from another tables
Bandanenilima wrote:
I want to add items from one table and can add year and month value from another tables
If your both datatables follow same structure, you can use DataTable.Merge[^]. But it looks like you have different structure. Obvious method would be to get a single data structure which has all the data required for binding. :)
Navaneeth How to use google | Ask smart questions