This documentation is archived and is not being maintained.

Table.GridLines Property

Gets or sets the grid line style to display in the Table control.

[Visual Basic]
Public Overridable Property GridLines As GridLines
[C#]
public virtual GridLines GridLines {get; set;}
[C++]
public: __property virtual GridLines get_GridLines();
public: __property virtual void set_GridLines(GridLines);
[JScript]
public function get GridLines() : GridLines;
public function set GridLines(GridLines);

Property Value

One of the GridLines enumeration values. The default value is None.

Remarks

Use the GridLines property to specify which cell borders are displayed in the Table control. The following table lists the different grid line styles.

GridLine value Description
None No cell borders are displayed.
Horizontal Only the horizontal cell borders are displayed.
Vertical Only the vertical cell borders are displayed.
Both Both the horizontal and vertical cell borders are displayed.

Example

[Visual Basic, C#] The following example demonstrates how to use the GridLines property to specify the grid line style.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <script runat="server">

      Sub Page_Load(sender As Object, e As EventArgs) 
        
         ' Generate rows and cells.
            
         Dim numrows As Integer = 5
         Dim numcells As Integer = 4

         Dim i As Integer
         Dim j As Integer
            
         For j = 0 to numrows - 1
            
            Dim r As TableRow = new TableRow()
                
            For i = 0 to numcells - 1 
            
               Dim c As TableCell = new TableCell()
               c.Controls.Add(New LiteralControl("row " & j.ToString() & _ 
                              ", cell " & i.ToString()))
               r.Cells.Add(c)

            Next i
                
            Table1.Rows.Add(r)

         Next j

      End Sub

      Sub Button_Click(sender As Object, e As EventArgs) 
      
         Table1.GridLines = CType(DropDown1.SelectedIndex, GridLines)
      
      End Sub

    </script>

</head>

<body>

   <h3>Table GridLines Example</h3>

   <form runat="server">

      <asp:Table id="Table1" 
           BorderColor="black" 
           BorderWidth="1" 
           GridLines="Both" 
           runat="server"/>

      <p>

      GridLines:

      <asp:DropDownList id="DropDown1" runat="server">
         <asp:ListItem Value="0">None</asp:ListItem>
         <asp:ListItem Value="1">Horizontal</asp:ListItem>
         <asp:ListItem Value="2">Vertical</asp:ListItem>
         <asp:ListItem Value="3">Both</asp:ListItem>
      </asp:DropDownList>

      <br>

      <asp:button id="Button1"
           Text="Display Table"
           OnClick="Button_Click" 
           runat=server/>
        
   </form>

</body>
</html>
    

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

   <script runat="server">

      void Page_Load(Object sender, EventArgs e)
      { 
        
         // Generate rows and cells.
            
         int numrows = 5;
         int numcells = 4;
            
         for(int j=0; j<=numrows - 1; j++)
         {
            
            TableRow r = new TableRow();
                
            for(int i=0; i <= numcells - 1; i++)
            {
            
               TableCell c = new TableCell();
               c.Controls.Add(new LiteralControl("row " + j.ToString() + 
                              ", cell " + i.ToString()));
               r.Cells.Add(c);

            }
                
            Table1.Rows.Add(r);

         }

      }

      void Button_Click(Object sender, EventArgs e)
      { 
      
         Table1.GridLines = (GridLines)DropDown1.SelectedIndex;
      
      }

    </script>

</head>

<body>

   <h3>Table GridLines Example</h3>

   <form runat="server">

      <asp:Table id="Table1" 
           BorderColor="black" 
           BorderWidth="1" 
           GridLines="Both" 
           runat="server"/>

      <p>

      GridLines:

      <asp:DropDownList id="DropDown1" runat="server">
         <asp:ListItem Value="0">None</asp:ListItem>
         <asp:ListItem Value="1">Horizontal</asp:ListItem>
         <asp:ListItem Value="2">Vertical</asp:ListItem>
         <asp:ListItem Value="3">Both</asp:ListItem>
      </asp:DropDownList>

      <br>

      <asp:button id="Button1"
           Text="Display Table"
           OnClick="Button_Click" 
           runat=server/>
        
   </form>

</body>
</html>
    

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Table Class | Table Members | System.Web.UI.WebControls Namespace | GridLines

Show: