ListView.EditIndex 속성

정의

편집하고 있는 항목의 인덱스를 가져오거나 설정합니다.

public:
 virtual property int EditIndex { int get(); void set(int value); };
public virtual int EditIndex { get; set; }
member this.EditIndex : int with get, set
Public Overridable Property EditIndex As Integer

속성 값

Int32

편집 중인 항목의 0부터 시작하는 인덱스입니다. 기본값은 -1로, 편집하고 있는 항목이 없음을 나타냅니다.

예외

EditIndex 속성이 -1보다 작은 값으로 설정된 경우입니다.

예제

다음 예제에서는 컨트롤에서 EditIndex 항목이 편집 모드 ListView 에 있는지 여부를 확인 하려면 속성을 사용 하는 방법을 보여 집니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 ListViewDataItem 클래스입니다.

protected void ContactsListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{

  //Verify there is an item being edited.
  if (ContactsListView.EditIndex >= 0)
  {

    //Get the item object.
    ListViewDataItem dataItem = (ListViewDataItem)e.Item;

    // Check for an item in edit mode.
    if (dataItem.DisplayIndex == ContactsListView.EditIndex)
    {

      // Preselect the DropDownList control with the Title value
      // for the current item.

      // Retrieve the underlying data item. In this example
      // the underlying data item is a DataRowView object.        
      DataRowView rowView = (DataRowView)dataItem.DataItem;

      // Retrieve the Title value for the current item. 
      String title = rowView["Title"].ToString();

      // Retrieve the DropDownList control from the current row. 
      DropDownList list = (DropDownList)dataItem.FindControl("TitlesList");

      // Find the ListItem object in the DropDownList control with the 
      // title value and select the item.
      ListItem item = list.Items.FindByText(title);
      list.SelectedIndex = list.Items.IndexOf(item);
                      
    }
  }
}
Protected Sub ContactsListView_ItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs) 
    
  'Verify there is an item being edited.
  If ContactsListView.EditIndex >= 0 Then
    
    'Get the item object.
    Dim dataItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
    
    ' Check for an item in edit mode.
    If dataItem.DisplayIndex = ContactsListView.EditIndex Then
        
      ' Preselect the DropDownList control with the Title value
      ' for the current item.
      ' Retrieve the underlying data item. In this example
      ' the underlying data item is a DataRowView object.        
      Dim rowView As DataRowView = CType(dataItem.DataItem, DataRowView)
      
      ' Retrieve the Title value for the current item. 
      Dim title As String = rowView("Title").ToString()
      
      ' Retrieve the DropDownList control from the current row. 
      Dim list As DropDownList = CType(dataItem.FindControl("TitlesList"), DropDownList)
      
      ' Find the ListItem object in the DropDownList control with the 
      ' title value and select the item.
      Dim item As ListItem = list.Items.FindByText(title)
      list.SelectedIndex = list.Items.IndexOf(item)
    End If 
  End If

End Sub

설명

속성을 사용하여 편집할 컨트롤의 EditIndex ListView 항목을 프로그래밍 방식으로 지정하거나 결정할 수 있습니다. 이 속성이 컨트롤에 있는 항목의 인덱스로 설정되면 해당 항목이 편집 모드로 표시됩니다. 편집 모드에서 항목은 템플릿 대신 템플릿을 EditItemTemplate 사용하여 렌더링됩니다 ItemTemplate . 사용자가 항목의 EditItemTemplate 값을 수정할 수 있도록 데이터 바인딩된 컨트롤을 채울 수 있습니다. 편집 모드에서 표시 모드로 전환하려면 이 속성을 -1로 설정합니다.

EditIndex 속성은 일반적으로 편집할 항목을 프로그래밍 방식으로 결정해야 하거나 컨트롤에 사용자 지정 편집 기능을 ListView 추가할 때 사용됩니다. 컨트롤에는 ListView 속성이 설정된 항목 템플릿 CommandName 에 단추를 추가하는 경우 항목을 편집 모드로 자동으로 배치하는 기본 제공 편집 기능이 있습니다 Edit.

적용 대상

추가 정보