System.Web.UI.WebControls Namespace BaseDataList Class
Sets or retrieves the amount of space between cells.
Inline |
<asp:basedatalist cellspacing = intPixels ... > |
Script |
BaseDataList.CellSpacing [ = intPixels ] |
intPixels |
Integer specifying the amount of space ( in pixels ) between adjacent cells. |
The property is read/write with a default value of -1, which indicates that no value is specified.
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.
NOTE: 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.
In a DataList control, this property applies only if the RepeatLayout property is set to Table.
The sample below shows how to programmatically set the CellSpacing property of a DataGrid at run time, depending on user input. The code also demonstrates how to add the user options to a selectable list dynamically.
void Page_Load ( Object src, EventArgs e ) {
if ( !IsPostBack ) {
for ( int i=1; i <= 15; i+=2 ) {
SpaceSelect.Items.Add ( i.ToString ( ) );
}
SpaceSelect.SelectedIndex = 2;
string query = "SELECT Lastname, Firstname, Address, City, Country FROM Employees";
myGrid.DataSource = fetchData ( query, "northwind" );
myGrid.DataBind ( );
}
myGrid.CellSpacing = int.Parse ( SpaceSelect.SelectedItem.Text );
}
Sub Page_Load ( src As Object, e As EventArgs )
If Not IsPostBack Then
Dim i As Integer
For i = 1 To 15 Step 2
SpaceSelect.Items.Add ( i.ToString ( ) )
Next i
SpaceSelect.SelectedIndex = 2
Dim query As String = "SELECT Lastname, Firstname, Address, City, Country FROM Employees"
myGrid.DataSource = fetchData ( query, "northwind" )
myGrid.DataBind ( )
End If
myGrid.CellSpacing = Integer.Parse ( SpaceSelect.SelectedItem.Text )
End Sub |
|
C# |
VB |
Show me
BaseDataList Members CellPadding GridLines