Click here to Skip to main content
15,845,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing an ASP.NET application which uses GridViews to display and edit data.

When my GridView is large enough to need a horizontal scroll bar, I want a Div tag with a scroll bar that allows the GridView to be scrolled while everything else still fits on the screen instead of scrolling the whole page.

I can do this with the max-width CSS property, but this only works for one size.

I can set an event in javascript to change the style property of the Div tag but then I need to change it everytime the window size changes, which isn't happening in IE 9. I also hate doing it this way. I want to control it with one CSS property that doesn't have to change.

This is the code I've used so far to do this for my prototype, but I need a better way to do this.

onresize = changewidth();

function changewidth() {
    "max-width: " + (document.body.offsetWidth - 10).toString() + "px;overflow-x:scroll;");


You may want to check out how it was done here: ASP.NET Splitter Bar - Resize panels, table cells, and controls[^].
Check out some of the articles in this search: splitter control[^]
Share this answer
ARBebopKid 16-May-12 15:24pm    
I don't need a two column control. Just how to get the one's I have to work correctly.
fjdiewornncalwe 16-May-12 16:27pm    
The concept is the same, but you just need to apply it to a single div instead of multiple divs.
ARBebopKid 16-May-12 16:32pm    
It's setting the width property to a pixel value. I want to use the page width whatever it is.
It's not the solution I was looking for but it works better than the window onresize event because it actually fires when it resizes.

<body onresize="changewidth();">

Visual Studio doesn't think this is valid, but IE does.
Share this answer
ARBebopKid 17-May-12 16:26pm    
I'll still take CSS solutions if anyone has them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900