views:

1006

answers:

4

Hi,

I'm currently implementing an RSS feeder control for a website. I'm planning to allow a limit of 10 items to be displayed on the homepage using a repeater control.

My question is how do I prevent the height of the control exceeding a certain dimension? I cannot guarantee how much content will be provided per RSS feed item.

One option I have considered is to limit the volume of content per item as a substring of the content but this is still providing a general approach.

Is there a way to determine how far down the page the control has renderred per control on the server side and abandon further binding once it has reached a limit? Or is the better approach to always render the 10 items then on page load check with javascript how much room each item takes up as a running total and hide anything after a limit?

Thanks,

Brian.

A: 

It is impossible to tell what the height is going to be on the server side. All the browsers render things slightly differently. Your best bet as you already suggested is to use javascript. Question is why is the height so important. I ask because typically web pages grow in height and that is well understood by the user and they are used to using the vertical scrollbar. The horizontal scrollbar seems messy and counter intuitive in a web environment.

uriDium
Height is important because there are multiple content columns on the site. The other columns are fixed heights but the dynamic content column is fixed for the height of the homepage and should only display content up until a height close to the container height to keep the layout as a fixed grid style alignment.
Brian Scott
+1  A: 

Add a div tag (or other appropriate block-level element, as you may already be using something like 'table') the the Header and Footer templates of the control, and use css to style the height and overflow of this element.

Joel Coehoorn
+1; for bonus points use the overflow property to make the div scroll internally.
Wyatt Barnett
Would this not just actually cut the content off? I'm looking to avoid seeing half an item's contents or having to introduce scroll bars.
Brian Scott
A: 

I'd definitely go for the javascript option out of the two; anything else would be too cumbersome (the solutions I can think of off the top of my head would involve actually keeping track of the height and width of every character for the specific font, and manually do a whole lot of char by char calculations) but another solution would be to look at a containing div with overflow: hidden

David Hedlund
Would overflow hidden not cut the content apart at the given height though? I don't want half an article and I don't want to present scrollbars on the homepage content.
Brian Scott
A: 

Hi,

I did it sometime back - you could have a scrollable repeater itself using the following code (should work as far as remember):

Whenever you are databinding the grid use the following peice of code to determin if the no of records exceed the page size you want to keep:

Example: Suppose you want to limt the page size to 10 then,

if (ds.Tables[0].Rows.Count > 10)
    myRepeater.Attributes["Style"] = "OVERFLOW-Y:auto;HEIGHT:200px;";
else
   myRepeater.Attributes["Style"] = "OVERFLOW-Y:auto;";

You have to tweak the Height according to what suits best with the UI.

MSIL