DataGrid.EditItemStyle 속성

정의

편집을 위해 DataGrid 컨트롤에서 선택된 항목의 스타일 속성을 가져옵니다.

public:
 virtual property System::Web::UI::WebControls::TableItemStyle ^ EditItemStyle { System::Web::UI::WebControls::TableItemStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public virtual System.Web.UI.WebControls.TableItemStyle EditItemStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.EditItemStyle : System.Web.UI.WebControls.TableItemStyle
Public Overridable ReadOnly Property EditItemStyle As TableItemStyle

속성 값

TableItemStyle

편집을 위해 TableItemStyle 컨트롤에서 선택된 항목의 스타일 속성을 포함하는 DataGrid 개체입니다. 기본값은 빈 TableItemStyle 개체입니다.

특성

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 EditItemStyle 속성을 노란색으로 편집을 위해 선택한 항목의 배경색을 설정 합니다.

<%@ 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 language="C#" runat="server">
 
    DataTable Cart = new DataTable();
    DataView CartView;   
 
    void Page_Load(Object sender, EventArgs e) 
    {
       DataRow dr;
 
       if (Session["ShoppingCart"] == null) 
       {       
 
          Cart.Columns.Add(new DataColumn("Qty", typeof(String)));
          Cart.Columns.Add(new DataColumn("Item", typeof(String)));
          Cart.Columns.Add(new DataColumn("Price", typeof(String)));
          Session["ShoppingCart"] = Cart;
             
          // Create sample data.
          for (int i = 1; i <= 4; i++) 
          {
             dr = Cart.NewRow();
             if (i % 2 != 0)
                dr[0] = "2";
             else
                dr[0] = "1";
             dr[1] = "Item " + i.ToString();
             dr[2] = (1.23 * (i + 1)).ToString();
             Cart.Rows.Add(dr);
          }
       }
       else
          Cart = (DataTable)Session["ShoppingCart"];          
 
       CartView = new DataView(Cart);
       CartView.Sort="Item";
 
       if (!IsPostBack)
          BindGrid(); 
                   
    }
 
    void MyDataGrid_Edit(Object sender, DataGridCommandEventArgs e) 
    {
       MyDataGrid.EditItemIndex = e.Item.ItemIndex;
       BindGrid();
    }
 
    void MyDataGrid_Cancel(Object sender, DataGridCommandEventArgs e) 
    {
       MyDataGrid.EditItemIndex = -1;
       BindGrid();
    }
 
    void MyDataGrid_Update(Object sender, DataGridCommandEventArgs e) 
    {
       // For bound columns, the edited value is stored in a TextBox.
       // The TextBox is the 0th element in the column's cell.
       TextBox qtyText = (TextBox)e.Item.Cells[2].Controls[0];
       TextBox priceText = (TextBox)e.Item.Cells[3].Controls[0];
 
       String item = e.Item.Cells[1].Text;
       String qty = qtyText.Text;
       String price = priceText.Text;
        
       DataRow dr;
 
       // With a database, use an update command to update the data. Because 
       // the data source in this example is an in-memory DataTable, delete the 
       // old row and replace it with a new one.

       // Remove old entry.
       CartView.RowFilter = "Item='" + item + "'";
       if (CartView.Count > 0)
          CartView.Delete(0);
       CartView.RowFilter = "";
 
       // Add new entry.
       dr = Cart.NewRow();
       dr[0] = qty;
       dr[1] = item;
       dr[2] = price;
       Cart.Rows.Add(dr);
 
       MyDataGrid.EditItemIndex = -1;
       BindGrid();
    }
 
    void BindGrid() 
    {
       MyDataGrid.DataSource = CartView;
       MyDataGrid.DataBind();
    }
 
 </script>
 
 <head runat="server">
    <title>DataGrid Editing Example</title>
</head>
<body style="font: 10pt verdana">
 
    <form id="form1" runat="server">
        
       <h3>DataGrid Editing Example</h3>
 
       <asp:DataGrid id="MyDataGrid" runat="server"
            BorderColor="black"
            BorderWidth="1"
            CellPadding="3"
            Font-Names="Verdana"
            Font-Size="8pt"
            OnEditCommand="MyDataGrid_Edit"
            OnCancelCommand="MyDataGrid_Cancel"
            OnUpdateCommand="MyDataGrid_Update"
            AutoGenerateColumns="false">

            <HeaderStyle BackColor="#aaaadd">
            </HeaderStyle>

            <EditItemStyle BackColor="yellow">
            </EditItemStyle>
 
          <Columns>
 
             <asp:EditCommandColumn
                  EditText="Edit"
                  CancelText="Cancel"
                  UpdateText="Update"
                  HeaderText="Edit Command Column">

                <ItemStyle Wrap="false">
                </ItemStyle>

               <HeaderStyle Wrap="false">
               </HeaderStyle>

             </asp:EditCommandColumn>
 
             <asp:BoundColumn HeaderText="Item" 
                  ReadOnly="true" 
                  DataField="Item"/>
 
             <asp:BoundColumn HeaderText="Quantity" 
                  DataField="Qty"/>
 
             <asp:BoundColumn HeaderText="Price" 
                  DataField="Price"/>
 
          </Columns>
 
       </asp:DataGrid>
 
    </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 language="VB" runat="server">
 
    Dim Cart As New DataTable
    Dim CartView As DataView
    
    Sub Page_Load(sender As Object, e As EventArgs)
        Dim dr As DataRow
        
        If Session("ShoppingCart") Is Nothing Then
            
            Cart.Columns.Add(New DataColumn("Qty", GetType(String)))
            Cart.Columns.Add(New DataColumn("Item", GetType(String)))
            Cart.Columns.Add(New DataColumn("Price", GetType(String)))
            Session("ShoppingCart") = Cart
            
            ' Create sample data.
            Dim i As Integer
            For i = 1 To 4
                dr = Cart.NewRow()
                If i Mod 2 <> 0 Then
                    dr(0) = "2"
                Else
                    dr(0) = "1"
                End If
                dr(1) = "Item " & i.ToString()
                dr(2) =(1.23 *(i + 1)).ToString()
                Cart.Rows.Add(dr)
            Next i
        Else
            Cart = CType(Session("ShoppingCart"), DataTable)
        End If 
        CartView = New DataView(Cart)
        CartView.Sort = "Item"
        
        If Not IsPostBack Then
            BindGrid()
        End If 
    End Sub 'Page_Load


    Sub MyDataGrid_Edit(sender As Object, e As DataGridCommandEventArgs)
        MyDataGrid.EditItemIndex = e.Item.ItemIndex
        BindGrid()
    End Sub 'MyDataGrid_Edit


    Sub MyDataGrid_Cancel(sender As Object, e As DataGridCommandEventArgs)
        MyDataGrid.EditItemIndex = - 1
        BindGrid()
    End Sub 'MyDataGrid_Cancel


    Sub MyDataGrid_Update(sender As Object, e As DataGridCommandEventArgs)
        ' For bound columns, the edited value is stored in a TextBox.
        ' The TextBox is the 0th element in the column's cell.
        Dim qtyText As TextBox = CType(e.Item.Cells(2).Controls(0), TextBox)
        Dim priceText As TextBox = CType(e.Item.Cells(3).Controls(0), TextBox)
        
        Dim item As String = e.Item.Cells(1).Text
        Dim qty As String = qtyText.Text
        Dim price As String = priceText.Text
        
        Dim dr As DataRow
        
        ' With a database, use an update command to update the data. Because 
        ' the data source in this example is an in-memory DataTable, delete the 
        ' old row and replace it with a new one.

        ' Remove old entry.
        CartView.RowFilter = "Item='" & item & "'"
        If CartView.Count > 0 Then
            CartView.Delete(0)
        End If
        CartView.RowFilter = ""
        
        ' Add new entry.
        dr = Cart.NewRow()
        dr(0) = qty
        dr(1) = item
        dr(2) = price
        Cart.Rows.Add(dr)
        
        MyDataGrid.EditItemIndex = - 1
        BindGrid()
    End Sub 'MyDataGrid_Update


    Sub BindGrid()
        MyDataGrid.DataSource = CartView
        MyDataGrid.DataBind()
    End Sub 'BindGrid
 
 </script>
 
 <head runat="server">
    <title>DataGrid Editing Example</title>
</head>
<body style="font: 10pt verdana">
 
    <form id="form1" runat="server">
        
       <h3>DataGrid Editing Example</h3>
 
       <asp:DataGrid id="MyDataGrid" runat="server"
            BorderColor="black"
            BorderWidth="1"
            CellPadding="3"
            Font-Names="Verdana"
            Font-Size="8pt"
            OnEditCommand="MyDataGrid_Edit"
            OnCancelCommand="MyDataGrid_Cancel"
            OnUpdateCommand="MyDataGrid_Update"
            AutoGenerateColumns="false">

            <HeaderStyle BackColor="#aaaadd">
            </HeaderStyle>

            <EditItemStyle BackColor="yellow">
            </EditItemStyle>
 
          <Columns>
 
             <asp:EditCommandColumn
                  EditText="Edit"
                  CancelText="Cancel"
                  UpdateText="Update"
                  HeaderText="Edit Command Column">

                <ItemStyle Wrap="false">
                </ItemStyle>

               <HeaderStyle Wrap="false">
               </HeaderStyle>

             </asp:EditCommandColumn>
 
             <asp:BoundColumn HeaderText="Item" 
                  ReadOnly="true" 
                  DataField="Item"/>
 
             <asp:BoundColumn HeaderText="Quantity" 
                  DataField="Qty"/>
 
             <asp:BoundColumn HeaderText="Price" 
                  DataField="Price"/>
 
          </Columns>
 
       </asp:DataGrid>
 
    </form>
 
 </body>
 </html>

설명

사용 하 여는 EditItemStyle 속성에서 편집을 위해 선택한 항목에 대 한 사용자 지정 스타일을 제공 하는 DataGrid 제어 합니다. 조정할 수 있는 공통 스타일 특성 전경색, 배경색, 글꼴 및 셀 내용 맞춤을 포함 합니다. 모양을 향상 시킬 다른 스타일을 사용 하 여 DataGrid 컨트롤입니다.

항목의 스타일 속성을 DataGrid 제어 계층을 통해 다른 하나씩 스타일 속성에서 상속 됩니다. 계층에서 낮은 설정 항목 스타일 속성은 계층 구조의 상위 항목 스타일 속성에 의해 상속 됩니다. 예를 들어 빨강 글꼴을 지정 하는 경우는 ItemStyle 속성을 다른 항목 스타일의 모든 속성을 DataGrid 컨트롤 빨강 글꼴을 갖게 됩니다. 이 옵션을 사용 하면 단일 항목의 스타일 속성을 설정 하 여 컨트롤에 공통 된 모양을 제공할 수 있습니다. 스타일 속성을 설정 하 여 상위 계층에 있는 항목 스타일 속성에 대 한 상속 된 스타일 설정을 재정의할 수 있습니다. 예를 들어, 파랑 글꼴을 지정할 수 있습니다 합니다 AlternatingItemStyle 속성에 지정 된 빨간색 글꼴로 재정의 ItemStyle 속성입니다. 다음 표에서 순위가 가장 높은 계층 순서를 나열합니다.

우선 순위 스타일 속성
1 EditItemStyle
2 SelectedItemStyle
3 AlternatingItemStyle
4 ItemStyle
5 ControlStyle

편집을 위해 선택한 항목에 대 한 사용자 지정 스타일을 지정 하려면 합니다 <EditItemStyle> 을 열고 닫는 태그 사이 DataGrid 제어 합니다. 다음을 표시 하 여 스타일 특성을 <EditItemStyle> 태그입니다.

적용 대상

추가 정보