System.Web.UI.WebControls Namespace BaseDataList Class
Sets or retrieves the amount of space between the contents of the cell and its borders.
Inline |
<asp:basedatalist cellpadding = intPixels ... > |
Script |
BaseDataList.CellPadding [ = intPixels ] |
intPixels |
Integer specifying the amount of space ( in pixels ) between the border and the contents of the cell. |
The property is read/write with a default value of -1, which indicates that no value is specified.
Use the CellPadding property to control the spacing between the contents of a cell and the cell's border. The amount of padding specified is added to all four sides of the cell.
All cells in the same column of a data listing control share the same cell width. Therefore, if the content of one cell is longer than the content other cells in the same column, the padding amount is applied to the widest cell. All other cells in the column are also set with this cell width.
Similarly, all cells in the same row share the same height. The padding amount is applied to the height of the tallest cell in the row. All other cells in the row are set with this cell height. Individual cell sizes cannot be specified.
The sample below shows how to programmatically set the CellPadding 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 ) {
PadSelect.Items.Add ( i.ToString ( ) );
}
PadSelect.SelectedIndex = 2;
string query = "SELECT Lastname, Firstname, Address, City, Country FROM Employees";
myGrid.DataSource = fetchData ( query, "northwind" );
myGrid.DataBind ( );
}
myGrid.CellPadding = int.Parse ( PadSelect.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
PadSelect.Items.Add ( i.ToString ( ) )
Next i
PadSelect.SelectedIndex = 2
Dim query As String = "SELECT Lastname, Firstname, Address, City, Country FROM Employees"
myGrid.DataSource = fetchData ( query, "northwind" )
myGrid.DataBind ( )
End If
myGrid.CellPadding = Integer.Parse ( PadSelect.SelectedItem.Text )
End Sub |
|
C# |
VB |
Show me
BaseDataList Members CellSpacing GridLines