navigation
 Friday, March 31, 2006

When paging just won't cut it, scrollbars come in handy. Fortunately, it is quite easy to add scrolling support to just about anything. All you need to do is wrap any of your controls in an HTML DIV tag.

The key to the code below is to set the DIV style to "OVERFLOW: auto;" and specify a size. When overflow is set to auto, scrollbars will automatically appear if  the control size exceeds the DIV's dimensions. The code below binds a datagird to the Order table in the Northwind database. This would normally produces a pretty large datagrid, but thanks to our DIV, we will only see a subsection of the data.

<DIV style="OVERFLOW: auto; WIDTH: 550px; HEIGHT: 200px">
<asp:datagrid id=DataGrid1 runat="server" DataSource="<%# dataView1 %>"
AutoGenerateColumns="False" ShowHeader="False">
<Columns>
<asp:BoundColumn DataField="OrderID"></asp:BoundColumn>
<asp:BoundColumn DataField="ShippedDate"></asp:BoundColumn>
<asp:BoundColumn DataField="ShipName"></asp:BoundColumn>
<asp:BoundColumn DataField="ShipCity"></asp:BoundColumn>
</Columns>
</asp:datagrid>
</DIV>
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, i, strike, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview