Click here to Skip to main content
15,889,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please,Can anyone help me in loading data as Rows(Not as Columns) of Gridview From Multiple Tables.Through Code.

Thanking You


With Regards
NanKi
Posted
Comments
amolpatil2243 22-Jan-12 23:42pm    
is the coulmns differ or remain same as gridview...
Nandakishore G N 22-Jan-12 23:44pm    
sorry Amol...I couldnt Follow....But,Columns Remain Same..

1) declare one data table
2) fetch whatever data you want
3) declare one data row to data table
4) arrange data as per your requirement in row
5) insert row into data table.
likewise this you can arrange data row wise from different tables

6) after adding all rows to data table assign this data table as data source to grid view


try it......


C#
DataTable oDtTemp = new DataTable();
for (int iCol = 0; iCol < dsIncentivePay.Tables[0].Columns.Count; iCol++)
{
        oDtTemp.Columns.Add(dsIncentivePay.Tables[0].Columns[iCol].ColumnName.ToString().Trim());
}

for (int iRwCount = 0; iRwCount < dsIncentivePay.Tables[0].Rows.Count; iRwCount++)
{
     DataRow oDrTemp = oDtTemp.NewRow();
     for (int iCol = 0; iCol < dsIncentivePay.Tables[0].Columns.Count; iCol++)
{
     oDrTemp[dsIncentivePay.Tables[0].Columns[iCol].ColumnName.ToString()] = dsIncentivePay.Tables[0].Rows[iRwCount]    [iCol].ToString();
}

     oDtTemp.Rows.Add(oDrTemp);
}
 
Share this answer
 
v3
Comments
Nandakishore G N 23-Jan-12 0:05am    
I'll Check It Out...Thanx Amol..
If you can not able to make a possible Select Query, then you can create datatable and bound with grid , other solution is select possible data by Query and Create template column in grid and add controls and you can assign values and you can change this values without making datatable again , all above solution is situational, what do you want ....
 
Share this answer
 
Hi,

Solution 1: Create stored procedure and call.......

Solution 2: create temporary table in sql,load the data from different table into the temporary table, then it is very easy to bind the data to Grid View or any other data bound controls...
 
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