BaseDataList.CellPadding 속성

정의

셀 내용과 셀 테두리 사이의 여백 크기를 가져오거나 설정합니다.

public:
 virtual property int CellPadding { int get(); void set(int value); };
[System.ComponentModel.Bindable(true)]
public virtual int CellPadding { get; set; }
public virtual int CellPadding { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.CellPadding : int with get, set
member this.CellPadding : int with get, set
Public Overridable Property CellPadding As Integer

속성 값

Int32

셀 내용과 셀 테두리 사이의 여백 크기(픽셀)입니다. 기본값은 -1로, 이 속성이 설정되어 있지 않음을 나타냅니다.

특성

예제

다음 코드 예제에서는 셀의 내용과 셀의 테두리 사이의 간격을 지정 하는 속성을 사용 CellPadding 하는 방법을 보여 줍니다.


<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <script runat="server">
 
      ICollection CreateDataSource() 
      {
      
         // Create sample data for the DataGrid control.
         DataTable dt = new DataTable();
         DataRow dr;
 
         // Define the columns of the table.
         dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
         dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
         dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
 
         // Populate the table with sample values.
         for (int i = 0; i < 9; i++) 
         {
            dr = dt.NewRow();
 
            dr[0] = i;
            dr[1] = "Item " + i.ToString();
            dr[2] = 1.23 * (i + 1);
 
            dt.Rows.Add(dr);
         }
 
         DataView dv = new DataView(dt);
         return dv;
      }
 
      void Page_Load(Object sender, EventArgs e) 
      {
 
         // Load sample data only once when the page is first loaded.
         if (!IsPostBack) 
         {
            ItemsGrid.DataSource = CreateDataSource();
            ItemsGrid.DataBind();
         }

      }

      void Index_Change(Object sender, EventArgs e) 
      {

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

      }
 
   </script>
 
<head runat="server">
    <title>BaseDataList CellPadding and CellSpacing Example</title>
</head>
<body>
 
   <form id="form1" runat="server">
 
      <h3>BaseDataList CellPadding and CellSpacing Example</h3>
 
      <asp:DataGrid id="ItemsGrid"
           BorderColor="black"
           BorderWidth="1"
           CellPadding="3"
           AutoGenerateColumns="true"
           runat="server">

         <HeaderStyle BackColor="#00aaaa">
         </HeaderStyle> 
 
      </asp:DataGrid>

      <br />

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

         <tr>

            <td>

               Cell padding:

            </td>

            <td>

               Cell spacing:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="CellPaddingList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Index_Change"
                    runat="server">

                  <asp:ListItem>0</asp:ListItem>
                  <asp:ListItem>1</asp:ListItem>
                  <asp:ListItem>2</asp:ListItem>
                  <asp:ListItem>3</asp:ListItem>
                  <asp:ListItem>4</asp:ListItem>
                  <asp:ListItem>5</asp:ListItem>

               </asp:DropDownList>

            </td>

            <td>

               <asp:DropDownList id="CellSpacingList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Index_Change"
                    runat="server">

                  <asp:ListItem>0</asp:ListItem>
                  <asp:ListItem>1</asp:ListItem>
                  <asp:ListItem>2</asp:ListItem>
                  <asp:ListItem>3</asp:ListItem>
                  <asp:ListItem>4</asp:ListItem>
                  <asp:ListItem>5</asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>

      </table>
 
   </form>
 
</body>
</html>

<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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)
 
            dt.Rows.Add(dr)

         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()
            ItemsGrid.DataBind()

         End If

      End Sub

      Sub Index_Change(sender As Object, e As EventArgs) 

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

      End Sub
 
   </script>
 
<head runat="server">
    <title>BaseDataList CellPadding and CellSpacing Example</title>
</head>
<body>
 
   <form id="form1" runat="server">
 
      <h3>BaseDataList CellPadding and CellSpacing Example</h3>
 
      <asp:DataGrid id="ItemsGrid"
           BorderColor="black"
           BorderWidth="1"
           CellPadding="3"
           AutoGenerateColumns="true"
           runat="server">

         <HeaderStyle BackColor="#00aaaa">
         </HeaderStyle> 
 
      </asp:DataGrid>

      <br />

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

         <tr>

            <td>

               Cell padding:

            </td>

            <td>

               Cell spacing:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="CellPaddingList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Index_Change"
                    runat="server">

                  <asp:ListItem>0</asp:ListItem>
                  <asp:ListItem>1</asp:ListItem>
                  <asp:ListItem>2</asp:ListItem>
                  <asp:ListItem>3</asp:ListItem>
                  <asp:ListItem>4</asp:ListItem>
                  <asp:ListItem>5</asp:ListItem>

               </asp:DropDownList>

            </td>

            <td>

               <asp:DropDownList id="CellSpacingList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Index_Change"
                    runat="server">

                  <asp:ListItem>0</asp:ListItem>
                  <asp:ListItem>1</asp:ListItem>
                  <asp:ListItem>2</asp:ListItem>
                  <asp:ListItem>3</asp:ListItem>
                  <asp:ListItem>4</asp:ListItem>
                  <asp:ListItem>5</asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>

      </table>
 
   </form>
 
</body>
</html>

설명

사용 된 CellPadding 셀 내용과 셀 테두리 사이의 간격을 제어 하는 속성입니다. 지정 된 안쪽 여백 크기를 셀의 네 변 모두에 추가 됩니다.

데이터 목록 컨트롤의 동일한 열에 있는 모든 셀은 동일한 셀 너비를 공유합니다. 따라서 한 셀의 내용이 같은 열에 있는 다른 셀의 내용보다 길면 안쪽 여백 양이 가장 넓은 셀에 적용됩니다. 열의 다른 모든 셀도 이 셀 너비로 설정됩니다.

마찬가지로 동일한 행의 모든 셀은 동일한 높이를 공유합니다. 안쪽 여백 크기는 행에서 가장 높은 셀의 높이에 적용됩니다. 행의 다른 모든 셀은 이 셀 높이로 설정됩니다. 개별 셀 크기를 지정할 수 없습니다.

적용 대상

추가 정보