ListViewEditEventArgs.NewEditIndex Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the index of the item that is being edited.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public int NewEditIndex { get; }

Property Value

Type: System.Int32

The index of the item that is being edited.

Use the NewEditIndex property to determine the index of the item that is being edited. The item index is often used to retrieve this item from the Items collection of the ListView control, which enables you to access the item's properties.

The following example shows how to use the NewEditIndex property to retrieve the ListViewItem object that is being edited. This code example is part of a larger example provided for the ListViewEditEventArgs class.

void ProductsListView_ItemEditing(Object sender, ListViewEditEventArgs e)
{
  ListViewItem item = ProductsListView.Items[e.NewEditIndex];
  Label dateLabel = (Label)item.FindControl("DiscontinuedDateLabel");

  if (String.IsNullOrEmpty(dateLabel.Text))
    return;

  //Verify if the item is discontinued.
  DateTime discontinuedDate = DateTime.Parse(dateLabel.Text);
  if (discontinuedDate < DateTime.Now)
  {
    Message.Text = "You cannot edit a discontinued item.";
    e.Cancel = true;
    ProductsListView.SelectedIndex = -1;
  }       
}

.NET Framework
Available since 3.5
Return to top
Show: