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?
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…
Try using following gridview's property: Double griwColWidth = this.Column1.ActualWidth.Value;
精彩评论