Gridview "columnization"
-
Hi, I'm not sure if this is possible at all, but my intention is to use the gridview to display the data in it in two columns next to eachother. Lets say i have just a string in my databinding and 10 rows. Then i wish to display it like this: row1 | row2 row3 | row4 row5 | row6 row7 | row8 row9 | row10 But as the gridview is making a table this cannot be done it seams. I have tried using itemtemplate and alternatetemplate but with no success as the gridview after each row inserts a new tr / td and ending thesame at the end. Is there anyway this can be done with the gridview or do i need to use repeaters and make my own paging for that? Thanks Daniel Tiru
-
Hi, I'm not sure if this is possible at all, but my intention is to use the gridview to display the data in it in two columns next to eachother. Lets say i have just a string in my databinding and 10 rows. Then i wish to display it like this: row1 | row2 row3 | row4 row5 | row6 row7 | row8 row9 | row10 But as the gridview is making a table this cannot be done it seams. I have tried using itemtemplate and alternatetemplate but with no success as the gridview after each row inserts a new tr / td and ending thesame at the end. Is there anyway this can be done with the gridview or do i need to use repeaters and make my own paging for that? Thanks Daniel Tiru
Yeah it is possible. Iterate through the results of your query. And convert each set of two rows into one. Then bind to the datatable. I didn't test the following code but you should get the idea.
DataTable dt = new DataTable(); DataColumn dc = new DataColumn("RowOdd", Type.GetType("System.Int32")); DataColumn dc1 = new DataColumn("RowEven", Type.GetType("System.Int32")); dt.Columns.Add(dc); dt.Columns.Add(dc1); Int16 Count = 0; DataRow r; while (YourDataReaderObject.read()) { if (Count = 0) { r = dt.NewRow(); r["RowOdd"] = dr.GetInt32(0); Count = 1; } else { r["RowEven"] = dr.GetInt32(1); dt.rows.add(r); Count = 0; } }
I didn't get any requirements for the signature
-
Yeah it is possible. Iterate through the results of your query. And convert each set of two rows into one. Then bind to the datatable. I didn't test the following code but you should get the idea.
DataTable dt = new DataTable(); DataColumn dc = new DataColumn("RowOdd", Type.GetType("System.Int32")); DataColumn dc1 = new DataColumn("RowEven", Type.GetType("System.Int32")); dt.Columns.Add(dc); dt.Columns.Add(dc1); Int16 Count = 0; DataRow r; while (YourDataReaderObject.read()) { if (Count = 0) { r = dt.NewRow(); r["RowOdd"] = dr.GetInt32(0); Count = 1; } else { r["RowEven"] = dr.GetInt32(1); dt.rows.add(r); Count = 0; } }
I didn't get any requirements for the signature
Thanks, i get the general idee, i have used the click/drag/drop functions in VS with data but that should i figure out how to do... But one thing more... as i in reality have more than one column, is this the right aproach? DataTable dt = new DataTable(); DataColumn dc = new DataColumn("RowOdd", Type.GetType("System.Int32")); DataColumn dc1 = new DataColumn("RowOdd1", Type.GetType("System.Int32")); DataColumn dc2 = new DataColumn("RowOdd2", Type.GetType("System.Int32")); DataColumn dc3 = new DataColumn("RowEven", Type.GetType("System.Int32")); DataColumn dc4 = new DataColumn("RowEven1", Type.GetType("System.Int32")); DataColumn dc5 = new DataColumn("RowEven2", Type.GetType("System.Int32")); dt.Columns.Add(dc); dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.Columns.Add(dc3); dt.Columns.Add(dc4); dt.Columns.Add(dc6); I think that should be fine... (I realized when writing the code) :) Thanks alot Tiru
-
Thanks, i get the general idee, i have used the click/drag/drop functions in VS with data but that should i figure out how to do... But one thing more... as i in reality have more than one column, is this the right aproach? DataTable dt = new DataTable(); DataColumn dc = new DataColumn("RowOdd", Type.GetType("System.Int32")); DataColumn dc1 = new DataColumn("RowOdd1", Type.GetType("System.Int32")); DataColumn dc2 = new DataColumn("RowOdd2", Type.GetType("System.Int32")); DataColumn dc3 = new DataColumn("RowEven", Type.GetType("System.Int32")); DataColumn dc4 = new DataColumn("RowEven1", Type.GetType("System.Int32")); DataColumn dc5 = new DataColumn("RowEven2", Type.GetType("System.Int32")); dt.Columns.Add(dc); dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.Columns.Add(dc3); dt.Columns.Add(dc4); dt.Columns.Add(dc6); I think that should be fine... (I realized when writing the code) :) Thanks alot Tiru
Yes, that looks correct to me. And you're welcome.
I didn't get any requirements for the signature
-
Hi, I'm not sure if this is possible at all, but my intention is to use the gridview to display the data in it in two columns next to eachother. Lets say i have just a string in my databinding and 10 rows. Then i wish to display it like this: row1 | row2 row3 | row4 row5 | row6 row7 | row8 row9 | row10 But as the gridview is making a table this cannot be done it seams. I have tried using itemtemplate and alternatetemplate but with no success as the gridview after each row inserts a new tr / td and ending thesame at the end. Is there anyway this can be done with the gridview or do i need to use repeaters and make my own paging for that? Thanks Daniel Tiru
As an alternative you could use a DataList and use its RepeateColumn feature.
-^-^-^-^-^- no risk no funk ................... please vote ------>
-
As an alternative you could use a DataList and use its RepeateColumn feature.
-^-^-^-^-^- no risk no funk ................... please vote ------>