Export (0) Print
Expand All
Expand Minimize
0 out of 2 rated this helpful - Rate this topic

ScrollBars Enumeration

Note: This enumeration is new in the .NET Framework version 2.0.

Specifies the visibility and position of scroll bars in a Panel control.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

[FlagsAttribute] 
public enum ScrollBars
/** @attribute FlagsAttribute() */ 
public enum ScrollBars
FlagsAttribute 
public enum ScrollBars
 Member nameDescription
AutoDisplays, horizontal, vertical, or both scroll bars as necessary. Otherwise, no scroll bars are shown. 
BothDisplays both a horizontal and a vertical scroll bar. 
HorizontalDisplays only a horizontal scroll bar. 
NoneDisplays no scroll bars. 
VerticalDisplays only a vertical scroll bar. 

The ScrollBars enumeration represents the visibility and position of the scroll bars in a Panel control. The ScrollBars property uses these enumeration values to specify the type of scroll bars to display in a Panel control. The default value for the ScrollBars property is None, indicating that no scroll bars are shown.

If you specify Auto for the ScrollBars property, scroll bars are automatically shown when the size of the content in a Panel control exceeds the size of the Panel control. For example, if a Panel control contains a table, and the panel is not wide enough to display all the rows in the table, a vertical scroll bar is shown. If the size of the table exceeds the height and width of the panel, both vertical and horizontal scroll bars are shown.

The following code example demonstrates how to declaratively set the ScrollBars property to Auto. The panel contains a table, the entire contents of which exceed the size of the panel. This causes both vertical and horizontal scroll bars to be automatically displayed when the panel is rendered. The user can then scroll to view all the data in the table.

<%@ Page Language="VB" %>

<html>
<head>
    <script runat="server">
        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
                
            ' Add more rows and columns to the table than can
            ' be displayed in the panel area.
            ' Scroll bars will be required to view all the data.
           
            ' Add rows and columns to the table.
            Dim i As Integer
            For i = 0 To 50
                Dim tempRow As New TableRow
                Dim j As Integer
                For j = 0 To 10
                    Dim tempCell As New TableCell
                    tempCell.Text = "(" & i & "," & j & ")"
                    tempRow.Cells.Add(tempCell)
                Next j
                Table1.Rows.Add(tempRow)
            Next i
                 
        End Sub

    </script>
</head>
<body>

    <form ID="Form1" runat="server">
        
        <h3>Panel.ScrollBars Property Example</h3>        
                
        <asp:Panel ID="Panel1"
            Height="300px"
            Width="400px"
            BackColor=Aqua
            ScrollBars=Auto
            runat=Server>
        
            <asp:Table ID="Table1"
                runat=Server>             
            </asp:Table>  
        
        </asp:Panel>         
         
    </form>
</body>
</html>

The following code example demonstrates the ScrollBars enumeration values. A ListBox control is populated with the ScrollBars enumeration values. The scroll bars displayed in the panel change, based on the value the user selects from the list box.

<%@ Page Language="VB" %>

<html>
<head>
    <script runat="server">
        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
                
            ' Add more rows and columns to the table than can
            ' be displayed in the panel area.
            ' Scroll bars will be required to view all the data.
           
            ' Add rows and columns to the table.
            Dim i As Integer
            For i = 0 To 50
                Dim tempRow As New TableRow
                Dim j As Integer
                For j = 0 To 10
                    Dim tempCell As New TableCell
                    tempCell.Text = "(" & i & "," & j & ")"
                    tempRow.Cells.Add(tempCell)
                Next j
                Table1.Rows.Add(tempRow)
            Next i
                 
        End Sub
   
        Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

            ' Determine which list item was clicked.
            ' Display the selected scroll bars in the panel.
            Select Case (ListBox1.SelectedIndex)
                Case 0
                    Panel1.ScrollBars = ScrollBars.None
                Case 1
                    Panel1.ScrollBars = ScrollBars.Horizontal
                Case 2
                    Panel1.ScrollBars = ScrollBars.Vertical
                Case 3
                    Panel1.ScrollBars = ScrollBars.Both
                Case 4
                    Panel1.ScrollBars = ScrollBars.Auto
                Case Else
                    Throw New Exception("You did not select a valid list item.")
            End Select

        End Sub
     
    </script>
</head>
<body>
    <form ID="Form1" runat="server">
        
        <h3>Panel.ScrollBars Property Example</h3>
        
        <h4>Select the scrollbars to display in the panel.</h4>
        
        <asp:ListBox ID="ListBox1"
            Rows=5
            AutoPostBack=True
            SelectionMode=Single
            OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"
            runat=Server>
                <asp:ListItem>None</asp:ListItem>
	        <asp:ListItem>Horizontal</asp:ListItem> 
	        <asp:ListItem>Vertical</asp:ListItem>
		<asp:ListItem>Both</asp:ListItem> 
		<asp:ListItem>Auto</asp:ListItem>              
        </asp:ListBox>
            
        <hr />              
        
        <asp:Panel ID="Panel1"
            Height="300px"
            Width="400px"
            BackColor=Aqua           
            runat=Server>            
            
            <asp:Table ID="Table1"
                runat=Server>             
            </asp:Table>
               
        </asp:Panel>           
         
    </form>
</body>
</html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.