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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. setting the columns width of a gridview

setting the columns width of a gridview

Scheduled Pinned Locked Moved ASP.NET
questiondatabasewpfhelp
7 Posts 2 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.
  • J Offline
    J Offline
    johland
    wrote on last edited by
    #1

    hi i have a gridview manually bounded to an accsess db. how can i adjust (in my case reduce) the width of specific columns? i've tried to set the width for the header,footer and item templates but all it did was narrowing an invisible text area - caused the text to wrap down but the size of the column remained the same... help on this will be very appreciated.. thanks j

    N 1 Reply Last reply
    0
    • J johland

      hi i have a gridview manually bounded to an accsess db. how can i adjust (in my case reduce) the width of specific columns? i've tried to set the width for the header,footer and item templates but all it did was narrowing an invisible text area - caused the text to wrap down but the size of the column remained the same... help on this will be very appreciated.. thanks j

      N Offline
      N Offline
      NeverHeardOfMe
      wrote on last edited by
      #2

      try, eg: ....Columns(1).ItemStyle.Width = System.Web.UI.WebControls.Unit.Percentage(30) or ....Columns(1).ItemStyle.Width = System.Web.UI.WebControls.Unit.Pixel(100)

      J 1 Reply Last reply
      0
      • N NeverHeardOfMe

        try, eg: ....Columns(1).ItemStyle.Width = System.Web.UI.WebControls.Unit.Percentage(30) or ....Columns(1).ItemStyle.Width = System.Web.UI.WebControls.Unit.Pixel(100)

        J Offline
        J Offline
        johland
        wrote on last edited by
        #3

        thanks Phil but i've tried that and didnt effect the columns width j

        N 1 Reply Last reply
        0
        • J johland

          thanks Phil but i've tried that and didnt effect the columns width j

          N Offline
          N Offline
          NeverHeardOfMe
          wrote on last edited by
          #4

          hmm, well... remember that web-controls are rendered on the page as straight HTML - tables in this case. Take a look at the page source of one of your pages and see the HTML code there - is there an appropriate in there? Assuming so, remember that the width may still display incorrectly if the other column widths are either not set or are contradictory...

          J 1 Reply Last reply
          0
          • N NeverHeardOfMe

            hmm, well... remember that web-controls are rendered on the page as straight HTML - tables in this case. Take a look at the page source of one of your pages and see the HTML code there - is there an appropriate in there? Assuming so, remember that the width may still display incorrectly if the other column widths are either not set or are contradictory...

            J Offline
            J Offline
            johland
            wrote on last edited by
            #5

            i've looked at the source code and width is appearing as i've set it, i.e. if i'm using: gridView.Columns[4].ItemStyle.Width = Unit.Percentage(30); i'm getting: td style="width:30%;" how do you think setting the width issue can be solved? thanks, J

            N 1 Reply Last reply
            0
            • J johland

              i've looked at the source code and width is appearing as i've set it, i.e. if i'm using: gridView.Columns[4].ItemStyle.Width = Unit.Percentage(30); i'm getting: td style="width:30%;" how do you think setting the width issue can be solved? thanks, J

              N Offline
              N Offline
              NeverHeardOfMe
              wrote on last edited by
              #6

              Then something else is throwing it off - you will have to examine the HTML to see what it might be: - something with a non-variable width (eg an image) that is wider than the column width allocated - are column widths set for ALL columns? - if so, are they contradictory (maybe they add up to only 90%, or 110%) - is an overall table width set? if so, does it tally with the sum of the column widths? - have you taken table borders, cellspacing and cellpadding into account, as well as margins/borders round objects within (eg images, again) - is this a browser-specific issue? All sorts of things can combine to throw off a table display - but at least you know the correct width is being applied via your code. All you need to do is figure out what's wrong in the resultant HTML and adjust things accordingly....

              J 1 Reply Last reply
              0
              • N NeverHeardOfMe

                Then something else is throwing it off - you will have to examine the HTML to see what it might be: - something with a non-variable width (eg an image) that is wider than the column width allocated - are column widths set for ALL columns? - if so, are they contradictory (maybe they add up to only 90%, or 110%) - is an overall table width set? if so, does it tally with the sum of the column widths? - have you taken table borders, cellspacing and cellpadding into account, as well as margins/borders round objects within (eg images, again) - is this a browser-specific issue? All sorts of things can combine to throw off a table display - but at least you know the correct width is being applied via your code. All you need to do is figure out what's wrong in the resultant HTML and adjust things accordingly....

                J Offline
                J Offline
                johland
                wrote on last edited by
                #7

                thanks... i will examine all that i can think of j

                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