Export (0) Print
Expand All
1 out of 7 rated this helpful - Rate this topic

Panel.ScrollBars Property

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

Gets or sets the visibility and position of scroll bars in a Panel control.

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

public virtual ScrollBars ScrollBars { get; set; }
/** @property */
public ScrollBars get_ScrollBars ()

/** @property */
public void set_ScrollBars (ScrollBars value)

public function get ScrollBars () : ScrollBars

public function set ScrollBars (value : ScrollBars)

Property Value

One of the ScrollBars enumeration values. The default is None.

Use the ScrollBars property to specify the visibility and position of scroll bars in a Panel control. This property is set using one of the ScrollBars enumeration values. The following table lists the possible values.

Value

Description

None

No scroll bars are shown.

Horizontal

Only a horizontal scroll bar is shown.

Vertical

Only a vertical scroll bar is shown.

Both

Both horizontal and vertical scroll bars are shown.

Auto

If necessary, horizontal, vertical, or both scroll bars are shown. Otherwise, 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 itself. 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.

NoteNote

This property is supported only on browsers that support HTML 4.0 or later.

TopicLocation
How to: Add Panel Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Add Panel Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications

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.

NoteNote

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.

<%@ 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 how to programmatically set the ScrollBars property. 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.

NoteNote

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.

<%@ 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.