SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From codebehind I add to my webpart controls

_grid=new SPGridView()
HtmlGenericControl div = new HtmlGenericControl("div");
                            div.Attributes.Add("id", "div-datagrid");
                            div.Attributes.Add("style", "overflow: auto;");

The problem is that entire page is scrolling instead only my grid.

Result is as on the picture:

enter image description here

How to enable scrolling only for that grid?

share|improve this question

You must set width in order to use overflow:auto. Try to set width:100%.

share|improve this answer

If you only need horizontal scroll set then I would use overflow-x: auto or overflow-x: scroll.

Difference is that browser can automatically decide if scroll is needed OR it will always show one (even if not necessarily needed). I have found that this is not always consistent behaviour. Sometimes browser will decide to scretch page rather than show scroll if you don't specify width on your grid (div that contains your grid).


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.