Using IList Remove method with a Custom DataType

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • a

    #1

    Using IList Remove method with a Custom DataType

    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.Teacher s[tId].Classes[cId].Students.Add(n ew 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.Studen t value", but I
    don't
    undertstand what to feed it to make it work. In the code below, I tried :
    Remove(new TCS.Student(nam e)).



    =============== =============== =============== ========

    protected void GridView_Studen ts_RowDeleting( object sender,
    GridViewDeleteE ventArgs e)
    {

    int tId = (DropDownList_T eachers.Selecte dIndex); // Index of Selected Teacher
    int cId = (DropDownList_C lasses.Selected Index); // Index of Selected Class

    string name = (GridView_Stude nts.Rows[e.RowIndex].Cells[2].Text); // Student
    Name

    Profile.Teacher s[tId].Classes[cId].Students.Remov e(new TCS.Student(nam e));//
    This line fails
    Populate_GridVi ew_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
Working...