I'm trying to delete an item from a collection, by clicking on a delete
button in a GridView control.
The item in the collection is stored in the Profile object (serialized as
xml in the ASPNETdb profile table).
The code to insert a new Student is:
Profile.Teachers[tId].Classes[cId].Students.Add(new TCS.Student(id, teacher,
class, name));
I'd like to use just the student name (stored in the GridView where the
Delete button is)
in the Remove method if that is possibl. I have a constructor for the
student that takes just
the student name. The Remove method is expecting "TCS.Student value", but I
don't
undertstand what to feed it to make it work. In the code below, I tried :
Remove(new TCS.Student(name)).
================================================== ===
protected void GridView_Students_RowDeleting(object sender,
GridViewDeleteEventArgs e)
{
int tId = (DropDownList_Teachers.SelectedIndex); // Index of Selected Teacher
int cId = (DropDownList_Classes.SelectedIndex); // Index of Selected Class
string name = (GridView_Students.Rows[e.RowIndex].Cells[2].Text); // Student
Name
Profile.Teachers[tId].Classes[cId].Students.Remove(new TCS.Student(name));//
This line fails
Populate_GridView_Students();
}
Any ideas what I need to do to Remove a student based upon
something other than an index number, like their name?
Thanks,
Paul