We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


GridView Column Width

mpdalton asked
Medium Priority
Last Modified: 2012-05-05
we have a gridview that we are manually setting up the columns in.

the column widths are defined by the user, but occasionly they specify a width that is smaller than required for the heading text.

the gridview automatically resizes the column and makes the other columns slightly smaller to fix this up.

the problem is that we dynamically add controls above and below the gridview to filtering and totalling so when the gridview is automatically resized the controls dont match up.

when we ask the column width, even after calling the databind method, it returns the width we set it as, not what it has been resized too.

how do i get the real column width.

note: when i talk about columns, i'm referrring to DataControlField's which are what dataview's call columns.
Watch Question

How is width set? By %? What are default settings for all columns (% or px)?


they are in px

Dim dgc As DataGridColumnStyle
   dgc = DataGrid1.TableStyles(0).GridColumnStyles("id")
   dgc.Width = 500
i suspect that what is happening is the browser is doing the 'resizing' to fit its contents. The code that your aspx page produces will have the correct column width for each column - but the browser needs to enlarge the column to fit it all in.

look at the page source of a page with problems and see what the column width is. this will tell you if its the aspx or the browser doing the resizing.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


hi solar_flare, you are right, the html is correct when i view the source, so it's the brower that is causing the problem.

any ideas how to override this behaviour so it maybe auto truncates the field or wraps it ? the column heading is already set to wrap but this only works when there are multiple words to a heading not one long word.
browsers would not be capable of truncating or wahtever, you would have to rename the columns so they are short enought to fit or change the font size

for each c as datacolumn in yourDatatable.Columns
    if c.ColumnName.Length > 10 then c.columnName = c.ColumnName.Substring(0, 10)


something like that in your codebehind would stop the headings being too long, butmight make it look ugly?

maybe resize the font of the header based on the length of the longest word so it wraps correctly? this would be more coding but might look better.


thanks for your help solar_flare. now that i know the limitiations of the browser i can let the project sponsor know that users will just have to check during table setup that the field width is wide enough.

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.