 |
|
 |
I've been trying for *hours* to get this sample code working... This is so ridiculous! Why not just include a download of the sample files?? Your commenting of code is useless. I've created DataSet and still nothing. What a waste of time. Next time include DOWNLOAD!!!
public partial class show_cpm3 : System.Web.UI.Page
{
DataAccess_Local objLocal = new DataAccess_Local();
DataTable dtNames;
private void BindData()
{
DataSet ds = objLocal.executedataset("SELECT CLEmpID, CLEmpName, CLEmpJobCode FROM empCallLog WHERE CLEmpID = '046354'");
DataSet new_ds = FlipDataSet(ds); DataView my_DataView = new_ds.Tables[0].DefaultView;
DataGrid1.DataSource = my_DataView;
DataGrid1.DataBind();
}
public DataSet FlipDataSet(DataSet my_DataSet)
{
DataSet ds = new DataSet();
foreach(DataTable dt in ds.Tables)
{
DataTable Table1 = new DataTable();
for(int i=0; i<=dt.Rows.Count; i++)
{
Table1.Columns.Add(Convert.ToString(i));
}
DataRow r;
for(int k=0; k<dt.Columns.Count; k++)
{
r = Table1.NewRow();
r[0] = dt.Columns[k].ToString();
for(int j=1; j<=dt.Rows.Count; j++)
r[j] = dt.Rows[j-1][k];
}
Table1.Rows.Add(r);
}
ds.Tables.Add(Table1);
}
}
|
|
|
|
 |
|
 |
Hi. This code is working fine. But i am unable to remove the column names. Although i removed 00, 01 such column names but i am unable to remove column names such as column0, column1 which is the first column in flipped dataset. Help me.
|
|
|
|
 |
|
 |
I am trying to rename the header 1 2 3 so it can match teh value.
Thanks
|
|
|
|
 |
|
 |
Dear Friends!
i have succesfully transposed my dataset table and it is displaying in the gridview fully editable but now the problem is how i can perform update.
i have catch RoW_updating event i am getting the new values but how can i get the primary key /column.
what i was trying is that after clicking on update button i again transposed the bind dataset table but this time i get old values only..
regards,
Sabir Awan
|
|
|
|
 |
|
 |
This Article very Good and working wel
|
|
|
|
 |
|
|
 |
|
 |
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = CreateDataTable(); GridView1.DataSource = dt; GridView1.DataBind(); //tranposed... GridView2.DataSource=Tranpose(dt); GridView2.DataBind(); } } DataTable Tranpose(DataTable dtOld) { DataTable dtNew=new DataTable(); DataColumn dcNew; DataRow drNew=null; //Create header column for (int i = 0; i < dtOld.Rows.Count; i++) { dcNew = new DataColumn(); if(i==0) { dcNew = new DataColumn(dtOld.Columns[0].ToString(), Type.GetType("System.String")); dtNew.Columns.Add(dcNew); } dcNew = new DataColumn(dtOld.Rows[i][0].ToString(), Type.GetType("System.String")); dtNew.Columns.Add(dcNew); } //put data for (int j = 1; j < dtOld.Columns.Count; j++) { drNew = dtNew.NewRow(); drNew[0] = dtOld.Columns[j].ColumnName.ToString(); for (int i = 0; i < dtOld.Rows.Count; i++) { //need to offset by one because of 1st column drNew[i+1] = dtOld.Rows[i][j].ToString(); } dtNew.Rows.Add(drNew); } return dtNew; }
DataTable CreateDataTable() { DataTable dt = new DataTable(); DataColumn dc = new DataColumn("BM", System.Type.GetType("System.Int32")); dc.AllowDBNull = false; dt.Columns.Add(dc); dc = new DataColumn("AF", System.Type.GetType("System.Int32")); dc.AllowDBNull = false; dt.Columns.Add(dc);
dc = new DataColumn("GA", System.Type.GetType("System.Int32")); dc.AllowDBNull = false; dt.Columns.Add(dc); DataRow dr; for (int i = 0; i<5; i++) { dr = dt.NewRow(); dr["BM"] = DateTime.Now.Year * 100 + DateTime.Now.Month + i; dr["AF"] = i; dr["GA"] = (i+1) * 2; dt.Rows.Add(dr); } return dt; }
|
|
|
|
 |
|
 |
Nice Jop Neeraj Jain,
but i found some bugs in your code so, i make anouther application shown your idea in a working Visual C#.NET 2005 Application.
here is the article link:
http://www.codeproject.com/useritems/Mmg.asp[^]
Mohamad Gamal
|
|
|
|
 |
|
 |
This is what I really need! thanks.
|
|
|
|
 |
|
 |
Here's some vb code to implment vertical handling of the column background colors
---------------------------------------
Public Sub datagrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles datagrid1.ItemDataBound
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
e.Item.Cells(0).BackColor = datagrid1.HeaderStyle.BackColor
Dim intCellCount As Integer = 1
For intCellCount = 1 To e.Item.Cells.Count - 1
If intCellCount Mod 2 = 0 Then
e.Item.Cells(intCellCount).BackColor = datagrid1.AlternatingItemStyle.BackColor
Else
e.Item.Cells(intCellCount).BackColor = datagrid1.ItemStyle.BackColor
End If
Next
End If
End Sub
-- modified at 16:24 Wednesday 2nd August, 2006
|
|
|
|
 |
|
 |
Help Me. How rotate datagrid with fields(bool, combobox, ets.) Please Help me.
Жизнь - как чашка чаю.
- Почему?
- А я что знаю? Я не философ.
|
|
|
|
 |
|
 |
Say for eg i just want to display first 5 columns and then when you hit next would like to display next 5 and so on and so forth...
-- modified at 19:50 Friday 23rd June, 2006
|
|
|
|
 |
|
 |
Does this code also work for GridView?
|
|
|
|
 |
|
 |
public DataSet FlipDataSet(DataSet my_DataSet)
{
DataSet ds = new DataSet();
foreach(DataTable dt in my_DataSet.Tables)
{
DataTable table = new DataTable();
for(int i = 0; i <= dt.Rows.Count; i++)
{
table.Columns.Add(Convert.ToString(i));
}
DataRow r = null;
for(int k = 0; k < dt.Columns.Count; k++)
{
r = table.NewRow();
r[0] = dt.Columns[k].ToString();
for(int j = 1; j <= dt.Rows.Count; j++)
r[j] = dt.Rows[j - 1][k];
table.Rows.Add(r);
}
ds.Tables.Add(table);
}
return ds;
}
ZoneTrader
-- modified at 18:47 Monday 17th April, 2006
|
|
|
|
 |
|
 |
"Keep things as simple as possible, but never simpler than that"
- Albert Einstein
Good Stuff.
|
|
|
|
 |
|
 |
There is some misplacing of one } in ur function named FlipDataSet()
The right one is
r[j] = dt.Rows[j-1][k];
table.Rows.Add(r);
}
ds.Tables.Add(table);
}
return ds;
}
Follow one lead one love all hate none
|
|
|
|
 |
|
 |
How can I apply formatting to my first column? Say, to make it bold? Normally I would do this with a header column. Is there a way I could set my first column as a header column? Is there a way to make individual cells bold? Awesome code by the way, Thank you!
|
|
|
|
 |
|
 |
Thank a lot. Code is usefull and explanatory
|
|
|
|
 |
|
 |
Call me crazy, but I like VB, here's the code:
Sub BindData()
Dim dsTBind as New Dataset()
dstBind = FlipDataSet(dsT)
Dim dv as new dataview
dv = dstBind.Tables(0).DefaultView
dg.datasource = dv
dg.databind()
End Sub
Function FlipDataSet(ods as dataset) as dataset
Dim ds as new dataset()
Dim dt as new datatable
Dim fdt as new datatable
Dim i as integer = 0
Dim k as integer = 0
Dim j as integer = 0
Dim r as datarow
for each dt in ods.tables
for i = 0 to dt.Rows.Count
fdt.Columns.Add(Convert.ToString(i))
next i
for k = 1 to dt.Columns.Count - 1
r = fdt.NewRow()
r(0) = dt.Columns(k).ToString()
for j = 1 to dt.Rows.Count
r(j) = dt.Rows(j-1)(k)
next j
fdt.Rows.Add(r)
next k
ds.Tables.Add(fdt)
next dt
FlipDataSet = ds
return FlipDataSet
end function
Just thought I'd put that out there, great code, great work. Lifesaver.
|
|
|
|
 |
|
 |
Hi brad,
thank you for this code...been looking for a vb.net equivelant for ages. I am still a newbie, but used to do crosstabs in MSAccess, having a hard time in .NET (avoiding SQL Server as it does not exist apparently unless u mention the fields - looking for something more dynamic)
Anyway my question is .. do u have the front end part for this code would love to see it all work..
thanks in advance
Jalal
|
|
|
|
 |
|
 |
Hey good job. I'm trying it but it gave me this error "Cannot find table 0. "? what is the problem here and how can it be solve.
PS. I'm using framework 1.1
The Developer - CEH
|
|
|
|
 |
|
 |
hi All,
i want to know if u can help me in this case:
Questions Answers
-----------------
Quest1 Answ1
Quest1 Answ2
Quest1 Answ3
Quest2 Answ1
Quest2 Answ2
Quest2 Answ3
to be ---->
Questions Answers1 Answer2 Answer3
-----------------------------------------------------------
Quest1 Answ1 answ2 answ3
Quest2 Answ1 answ2 answ3
thx in advance,Amr
|
|
|
|
 |
|
 |
Hi
if i wants to add image button ,push button or hyperlink in datagrid than is it possible? will it be displayed horizonataly like u'r data? i tried but it was displayed in a single column not in a single row.how i can do that.
is it possible to add a row in dataset wich contain imagebutton controls?
i hope u will help me.
thanks
|
|
|
|
 |
|
 |
Hi guys
I want to add edit,save,delete functionalities to the rows of this grid.
Please help
ThanX
Anz
|
|
|
|
 |
|
 |
Hi Guys
I just to know if some got the .NEt version working???
OZZY
Thank you!!!!1
|
|
|
|
 |