[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12285
  • Last Modified:

GridView Column Width

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.
0
mpdalton
Asked:
mpdalton
1 Solution
 
aki4uCommented:
How is width set? By %? What are default settings for all columns (% or px)?
0
 
mpdaltonAuthor Commented:
they are in px
0
 
SystemExpertCommented:

Dim dgc As DataGridColumnStyle
   dgc = DataGrid1.TableStyles(0).GridColumnStyles("id")
   dgc.Width = 500
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Solar_FlareCommented:
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.
0
 
mpdaltonAuthor Commented:
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.
0
 
Solar_FlareCommented:
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

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

next

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.
0
 
mpdaltonAuthor Commented:
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.

cheers.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now