SelectedIndex is "The zero-based index of the selected item in a ListView control. The default is -1, which indicates that no item is currently selected." (from
MSDN[
^])...So you should check if it is NOT -1 to be sure that any item has been selected...
if(ListView1.SelectedIndex != -1)
{
int idx = ListView1.SelectedIndex;
TextBox GarageEmail.Text = (TextBox)this.ListView1.Items[idx].FindControl("SupplierEmailAddress");
}
Now for the second line...It is completely wrong? The left side part if the text property of a TextBox (not clear from where it comes), where the right side is a TextBox control...You probably meant to do something like this:
TextBox GarageEmail = (TextBox)this.ListView1.Items[idx].FindControl("SupplierEmailAddress");