Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have simple grid view like below..all data i'm fetching from the database...and each columns are dynamic,like user can add more earnings to the database and that earning will come to the grid view


EmpNameEarningsAmount
AustinHRA1000$
AustinDA1000$
AustinBasic1000$


now i have to make above grid view as below



AustinHRADABasic
1000$1000$1000$


can you please suggest me some idea and examples using C# to do it..actually i'm just new to asp.net and i don have idea to do it
Posted
Updated 18-Jul-11 20:42pm
v2

I have recently writen an article about dynamic pivotting. In 7 steps it is shown how to create a pivot with summings of each column and row.

You do not need to go hat far but with the information in this link you should be able to tackle this simple gimmick
 
Share this answer
 
take a look at this article [^]- it may shed some light on it for you.
 
Share this answer
 
If any one face this kind of proble plese refer this code

SqlCommand cmd = new SqlCommand("Your query", con);
            SqlDataReader rdr;
            rdr = cmd.ExecuteReader();

            DataTable dt = new DataTable();

            DataRow newRow = dt.NewRow();


            DataColumn dc = new DataColumn();


            rdr.Read();
            dt.Columns.Add(new DataColumn(rdr[Index].ToString()));
            rdr.Close();

            rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {

                dt.Columns.Add(new DataColumn(rdr[Index].ToString()));
            }

            rdr.Close();
            rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                string Amount = rdr[Index].ToString();
                string EarnName = rdr[Index].ToString();
                newRow[EarnName] = Amount;


            }
            dt.Rows.Add(newRow);

            GridView1.DataSource = dt;
            GridView1.DataBind();
 
Share this answer
 
v3
Comments
[no name] 20-Jul-11 7:41am    
Edited for Code Block.
Nagy Vilmos 22-Jul-11 3:23am    
Strike Three! You're out!

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