Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Gridview "columnization"

Gridview "columnization"

Scheduled Pinned Locked Moved ASP.NET
question
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dTiru
    wrote on last edited by
    #1

    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

    T U 2 Replies Last reply
    0
    • D dTiru

      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

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • T ToddHileHoffer

        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

        D Offline
        D Offline
        dTiru
        wrote on last edited by
        #3

        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

        T 1 Reply Last reply
        0
        • D dTiru

          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

          T Offline
          T Offline
          ToddHileHoffer
          wrote on last edited by
          #4

          Yes, that looks correct to me. And you're welcome.

          I didn't get any requirements for the signature

          1 Reply Last reply
          0
          • D dTiru

            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

            U Offline
            U Offline
            Urs Enzler
            wrote on last edited by
            #5

            As an alternative you could use a DataList and use its RepeateColumn feature.

            -^-^-^-^-^- no risk no funk ................... please vote ------>

            D 1 Reply Last reply
            0
            • U Urs Enzler

              As an alternative you could use a DataList and use its RepeateColumn feature.

              -^-^-^-^-^- no risk no funk ................... please vote ------>

              D Offline
              D Offline
              dTiru
              wrote on last edited by
              #6

              Hi, yes thats true, didnt know about that one... but the downside is that i then have to make my own pager... A bit to overkill for me at the moment i think. Thanks /Tiru

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups