Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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;");
                            div.Controls.Add(_grid);
                            Controls.Add(div);

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

2 Answers 2

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).

Reference: http://www.w3schools.com/cssref/css3_pr_overflow-x.asp

share|improve this answer

Your Answer

 
discard

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.