views:

888

answers:

2

I have a gridview control that can get loaded with multiple pages worth of data. When I switch pages, the columns widths will change to accommodate the largest value in the column for that page.

If possible, I would like to set the widths of each column to the widest necessary width for the entire dataset.

+1  A: 

You can set the ItemStyle-Width property on each TemplateField, BoundField, etc. in your gridview to whatever you want. That should hold across paging. You will want to either not set the gridview width, or be sure you don't use a percentage if you do.

If you want to figure this out dynamically, you will have to examine your data first, before binding your grid, figure out the width that you want, then bind your gird and dynamically set the ItemStyle-Width in the RowDataBound event of the gridview.

JasonS
This is pretty obvious when I think about it, thanks. However, is there a good way to determine how many pixels wide a particular string will take up?
Loki Stormbringer
A: 

Tring things, in the edit colum menu of your grid you should try the auto size mode, I configure my to cell and it work pretty well for my needs..

This is available when you are not autogenerating the columns.

Try it.

Gerardo Jaramillo