Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CellSpacing Property

BaseDataList.CellSpacing Property

Gets or sets the amount of space between cells.

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

Public Overridable Property CellSpacing As Integer

Property Value

Type: System.Int32
The amount of space (in pixels) between cells. The default value is 0.

Use the CellSpacing property to control the spacing between adjacent cells in a data listing control. This spacing is applied both vertically and horizontally. The cell spacing is uniform for the entire data listing control. Individual cell spacing between each row or column cannot be specified.


If you set this property to a value greater than 0 and set the GridLines property to a value that displays the cell borders, a gap is displayed between the borders of adjacent cells. In this situation, the CellSpacing property controls the size of the gap.

The following code example demonstrates how to use the CellSpacing property to specify the spacing between adjacent cells.

<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >
   <script runat="server">

      Function CreateDataSource() As ICollection 

         ' Create sample data for the DataGrid control.
         Dim dt As DataTable = New DataTable()
         Dim dr As DataRow

         ' Define the columns of the table.
         dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
         dt.Columns.Add(New DataColumn("StringValue", GetType(string)))
         dt.Columns.Add(New DataColumn("CurrencyValue", GetType(double)))

         ' Populate the table with sample values.
         Dim i As Integer

         For i = 0 to 8 

            dr = dt.NewRow()

            dr(0) = i
            dr(1) = "Item " & i.ToString()
            dr(2) = 1.23 * (i + 1)


         Next i

         Dim dv As DataView = New DataView(dt)
         Return dv

      End Function

      Sub Page_Load(sender As Object, e As EventArgs) 

         ' Load sample data only once when the page is first loaded.
         If Not IsPostBack Then 

            ItemsGrid.DataSource = CreateDataSource()

         End If

      End Sub

      Sub Index_Change(sender As Object, e As EventArgs) 

         ItemsGrid.CellPadding = CellPaddingList.SelectedIndex
         ItemsGrid.CellSpacing = CellSpacingList.SelectedIndex

      End Sub


<head runat="server">
    <title>BaseDataList CellPadding and CellSpacing Example</title>

   <form id="form1" runat="server">

      <h3>BaseDataList CellPadding and CellSpacing Example</h3>

      <asp:DataGrid id="ItemsGrid"

         <HeaderStyle BackColor="#00aaaa">


      <br />

      <h4>Select different values for the cell padding and cell spacing:</h4>
      <table cellpadding="5">



               Cell padding:



               Cell spacing:





               <asp:DropDownList id="CellPaddingList"





               <asp:DropDownList id="CellSpacingList"








.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
© 2015 Microsoft