Search code examples
asp.netgridviewgetwidthcell

Getting the value of a Gridview column width in ASP when set dynamically


I couldn't find anything about getting the width of a gridview column or cell when they are not set specifically in aspx or in the code behind. Whenever I try something like this:

gridView.Rows[1].Cells[0].Width.Value

I get a value of 0 even though the actual value is not 0.

Anybody tried this?


Solution

  • You are wanting client-side information in a server-side script. To obtain this you will have to use javascript in the client page, get the value, and pass back to the server script as a hidden fields or something similar. The info will not be present the first time you hit the page. Also, the info may change and no longer represent the current state of the client. You might consider writing javascript to run on the client, doing whatever is required there, instead of server-side.