tags:

views:

562

answers:

2

Anyone know if it possible at run-time to know how many pixels high an asp.net gridview is?

I have a gridview on the left of my page. On the right side, I populate with random images that vary in height and I would like to (as close as possible) match the total height of the gridview with the sum total heights of the pictures on the right. (The code keeps checking for pictures until it find ones with the right height).

I can approximate the height by knowing the number of rows (gridview.rows.count * an average row height), but since row heights can vary depending on if they are long lines wrapping, I'd prefer to try and get a better height estimate...

Thx!

A: 

well Height is a property, so I'm guessing:

int heightGV = GridView1.Height;

I could very well be wrong though, because I've never done it. Try it and let us know.

BBetances
A: 

In all likelihood you're going to need to deal with this using client side scripting. There are techniques in javascript for determining the actual height in pixels of elements on the page that you could use.

The downside here is that you wouldn't have access to this info while the page is loading on the server side.

As an alternative, you could apply some styling to the grid to better control how high each row would be, and then implement paging so you can always know about how high the grid is.

In the past I've impelemented a fixed height gridview with a "frozen" header and a scrollable div wrapped around it, so I always at least knew the max height of the grid (obviously if you don't hit that max then the height is still variable).

There's a bunch of resources out there on how to do this, this article looks pretty good: GridView with frozen header

Jesse Taber