R – How to get width of gridview column when AutoGenerateColumns is true

asp.netautogeneratecolumngridviewwidth

I have a gridview that I need to get the width of columns for after the gridview is databound. I have to have AutoGenerateColumns=true because the columns for the datatable that the gridview is bound to is not going to be fixed. The problem I'm having is the gridview columns collection is not populated when AutoGenerateColumns is true. Is there anyway I can get the width of each column after the gridview is databound? I've tried using RowDataBound and going through the tablecells but the width is 0 for every column.

Best Answer

Unless you are setting the width of the column to a specific size (you aren't) you can't possibly know the width of the generated column until at least the render Page_Render event. The control's html does not exist until then and its width can't be known until the page is rendered into html and the css attached processed.