ListViewDataItem.DataItem 속성

정의

ListViewItem 개체가 바인딩된 내부 데이터 개체를 가져오거나 설정합니다.

public virtual object DataItem { get; set; }
public override object DataItem { get; set; }

속성 값

ListViewItem 개체가 바인딩된 내부 데이터 개체입니다.

예제

다음 예제에서는 사용 하는 방법을 보여 줍니다는 DataItem 속성 필드 값을 검색 합니다. 값은 다음 사전에서 항목을 선택 하는 데 사용 됩니다는 DropDownList 항목 편집 모드일 때 표시 되는 컨트롤입니다. 이 코드 예제는 제공 된 큰 예제의 일부는 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);
                      
    }
  }
}

설명

DataItem 만 도중 및 이후에 속성을 사용할 수는 ItemDataBound 이벤트는 ListView 컨트롤입니다.

적용 대상

제품 버전
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

추가 정보