Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Student English Tamil Maths Science Social

A 70 75 80 90 75
B 60 55 70 85 60
C 50 60 70 75 63


using foreach loop, from the above Datagridview i want as follows
how can i do please help me

A Englsih 70,Tamil 75,Maths 80,Science 90,Social 75
B Englsih 60,Tamil 55,Maths 70,Science 85,Social 60
C Englsih 50,Tamil 60,Maths 70,Science 75,Social 63



how can i do in asp.net using C#.

Regards,
Narasiman P.
Posted

 
Share this answer
 
I used this code to flip data ,column as rows ,may this idea will help you in windows application using c#


C#
Globaldata.SQLQuery = "select * from table" 

           

            OdbcDataAdapter first = new OdbcDataAdapter(Globaldata.SQLQuery, con);

            DataTable oldTable = ds.Tables.Add("first");

            first.Fill(ds, "first");           

            DataTable firsttable = new DataTable();

            firsttable.Columns.Add("Parametere");
            for (int i = 0; i < oldTable.Rows.Count; i++)
                firsttable.Columns.Add("Values"+i);

            for (int i = 0; i < oldTable.Columns.Count; i++)
            {
                DataRow newRow = firsttable.NewRow();

	            newRow[0] = oldTable.Columns[i].Caption;
	            for (int j = 0; j < oldTable.Rows.Count; j++)
		            newRow[j+1] = oldTable.Rows[j][i];
                firsttable.Rows.Add(newRow);
            }

            ds.Tables.Remove(oldTable);
            ds.Tables.Add(firsttable);
 
Share this answer
 
v2

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