Chris
Chris

Reputation: 7611

Get width of column/cell in GridView when 'width' property on column/cell is not set

I have a GridView, in which the width of each column is dynamic and changes depending on the dataset. I need to get the width of each column for use in my PDF exporter, but the column/cells width is always '0', presumably because I haven't set the width property.

Is there a way around this?

Upvotes: 2

Views: 2580

Answers (2)

Vihana Kewalramani
Vihana Kewalramani

Reputation: 925

Try using following gridview's property: Double griwColWidth = this.Column1.ActualWidth.Value;

Upvotes: 1

Rozwel
Rozwel

Reputation: 2020

I don’t know of a way to do this purely in the code behind, if someone else does I would love to hear about it.

What does occur to me as one possible way to accomplish this would be to add a hidden field to the page and then use JavaScript to populate the hidden field with the rendered column widths. This is assuming that you are displaying a standard ASPX page and giving the users an option to export to PDF. Your export code can then use the value of the hidden field to build the PDF layout. Doing it this way would be a bit of a kludge but it should work.

Hoping someone else has a better option…

Upvotes: 1

Related Questions