Aracılığıyla paylaş


ListView.EditIndex Özellik

Tanım

Düzenlenen öğenin dizinini alır veya ayarlar.

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

Özellik Değeri

Int32

Düzenlenmekte olan öğenin sıfır tabanlı dizini. Varsayılan değer -1'dir ve bu da hiçbir öğenin düzenlenmekte olmadığını gösterir.

Özel durumlar

EditIndex özelliği -1 değerinden küçük bir değere ayarlanır.

Örnekler

Aşağıdaki örnekte, bir öğenin denetimde EditIndex düzenleme modunda olup olmadığını belirlemek için özelliğinin ListView nasıl kullanılacağı gösterilmektedir. Bu kod örneği, sınıfı için ListViewDataItem sağlanan daha büyük bir örneğin parçasıdır.

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

Açıklamalar

Bir denetimdeki hangi öğenin ListView düzenleneceğini EditIndex program aracılığıyla belirtmek veya belirlemek için özelliğini kullanabilirsiniz. Bu özellik denetimdeki bir öğenin dizinine ayarlandığında, bu öğe düzenleme modunda görüntülenir. Düzenleme modunda, öğe şablon yerine ItemTemplate şablon kullanılarak EditItemTemplate işlenir. kullanıcıların öğenin değerlerini değiştirmesini sağlamak için öğesini veriye bağlı denetimlerle doldurabilirsiniz EditItemTemplate . Düzenleme modundan görüntüleme moduna geçmek için bu özelliği -1 olarak ayarlayın.

EditIndex Özelliği genellikle hangi öğenin düzenlendiğini program aracılığıyla belirlemeniz gerektiğinde veya denetime ListView özel düzenleme işlevi eklerken kullanılır. Özelliği ListView olarak ayarlanmış Editöğe şablonuna CommandName bir düğme eklerseniz, denetimin bir öğeyi otomatik olarak düzenleme moduna geçiren yerleşik bir düzenleme özelliği vardır.

Şunlara uygulanır

Ayrıca bkz.