Instead of grid view. Construct ure data using Dynamic tables. You can create any hell of a gridview(nested, dented,painted), once you know how to create dynamic tables: Follow the example below or just google you will get great results:
private void CreateDynamicTable()
{
PlaceHolder1.Controls.Clear();
// Fetch the number of Rows and Columns for the table
// using the properties
int tblRows = Rows;
int tblCols = Columns;
// Create a Table and set its properties
Table tbl = new Table();
// Add the table to the placeholder control
PlaceHolder1.Controls.Add(tbl);
// Now iterate through the table and add your controls
for (int i = 0; i < datable.Rows.Count; i++)
{
TableRow tr = new TableRow();
for (int j = 0; j < datable.Columns.Count; j++)
{
TableCell tc = new TableCell();
TextBox txtBox = new TextBox();
txtBox.Text = "RowNo:" + i + " " + "ColumnNo:" + " " + j;
// Add the control to the TableCell
tc.Controls.Add(txtBox);
// Add the TableCell to the TableRow
tr.Cells.Add(tc);
}
// Add the TableRow to the Table
tbl.Rows.Add(tr);
}
}
Or use nested gridview(may be complicated in ure case):
Maybe you should use SQL convertion,here's the sample:
【Your SQL's table】
A B C
1 1 11
1 11 1
22 2 32
3 42 1
52 4 5
【Your SQL statement】
declare @sql varchar(2000)set @sql=''select @sql=@sql+',max(case B when '+cast(B as varchar(10))+' then c end) ['+cast(B as varchar(10))+']' from (Select distinct B from TB) xset @sql='select A'+@sql+' from (select A,B,count(distinct C) c from tbgroup by A,B) vgroup by a'exec(@sql)
PleHelpMePls
None
0 Points
12 Posts
Please help me
Dec 28, 2012 07:31 AM|LINK
Hi,
First of all. Sorry if I'm in the wrong thread.
I'm new in Microsoft Visual Studio 2005. I'm having a hard time here. Originally the data looks like this on GridView:
Subject Name Score Total
Math Roy 90 90
Math Jack 81 81
Science Jack 87 87
What i want to be is like this:
Name Subject Total
Math Science
Roy 90 90
Jack 81 87 168
Is it possible?
p/s: The subject and the name are not hard coded.
alankarp
Contributor
2042 Points
345 Posts
Re: Please help me
Dec 28, 2012 07:46 AM|LINK
you can do it by using pivoting either in SQL or from C# see below example
http://www.codeproject.com/Articles/25167/Simple-Advanced-Pivots-with-C-and-ASP-NET
Profile
Naved Hasan ...
Participant
1005 Points
212 Posts
Re: Please help me
Dec 28, 2012 10:09 AM|LINK
Instead of grid view. Construct ure data using Dynamic tables. You can create any hell of a gridview(nested, dented,painted), once you know how to create dynamic tables: Follow the example below or just google you will get great results:
private void CreateDynamicTable() { PlaceHolder1.Controls.Clear(); // Fetch the number of Rows and Columns for the table // using the properties int tblRows = Rows; int tblCols = Columns; // Create a Table and set its properties Table tbl = new Table(); // Add the table to the placeholder control PlaceHolder1.Controls.Add(tbl); // Now iterate through the table and add your controls for (int i = 0; i < datable.Rows.Count; i++) { TableRow tr = new TableRow(); for (int j = 0; j < datable.Columns.Count; j++) { TableCell tc = new TableCell(); TextBox txtBox = new TextBox(); txtBox.Text = "RowNo:" + i + " " + "ColumnNo:" + " " + j; // Add the control to the TableCell tc.Controls.Add(txtBox); // Add the TableCell to the TableRow tr.Cells.Add(tc); } // Add the TableRow to the Table tbl.Rows.Add(tr); } }Or use nested gridview(may be complicated in ure case):
http://www.aspdotnet-suresh.com/2012/05/gridview-with-in-gridview-or-nested.html
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Please help me
Dec 29, 2012 12:49 AM|LINK
Hi,
Maybe you should use SQL convertion,here's the sample:
【Your SQL's table】
【Your SQL statement】
PleHelpMePls
None
0 Points
12 Posts
Re: Please help me
Dec 31, 2012 12:35 AM|LINK
Thx for the replies...
PleHelpMePls
None
0 Points
12 Posts
Re: Please help me
Dec 31, 2012 02:51 AM|LINK
Do i have to change or just stick to Gridview?
PleHelpMePls
None
0 Points
12 Posts
Re: Please help me
Dec 31, 2012 03:04 AM|LINK
what is @sql means for?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Please help me
Dec 31, 2012 03:33 AM|LINK
Just stick to GridView.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Please help me
Dec 31, 2012 03:33 AM|LINK
"@sql" means the variable in SQL's defination.
PleHelpMePls
None
0 Points
12 Posts
Re: Please help me
Jan 01, 2013 12:27 AM|LINK
with pivoting, what should i use for a table? Gridview or datalist? or is there any other data format that can be use for pivoting?