title: DataTable Rows.IndexOf()
body: <p>I am trying to find a row and then delete that row from a datatable. I keep getting nIndex = -1. Anyone have suggestions?</p>
  
  <pre><code>protected void cbxSelected_CheckedChanged(object sender, EventArgs e)
  {
   CheckBox checkbox = (CheckBox)sender;
   GridViewRow row = (GridViewRow)checkbox.NamingContainer;
   string sSampleId = row.Cells[1].Text;
  
   if (!string.IsNullOrEmpty(sSampleId))
   {
    DataTable dt;
  
    if (ViewState["dtTemp"] != null)
    {
     dt = (DataTable)ViewState["dtTemp"];
    }
    else
    {
     dt = new DataTable();
     dt.Columns.Add("sample_id");
    }
  
    DataRow dr;
    string[] drow = new string[] { sSampleId };
    dr = dt.NewRow();
    dr.ItemArray = drow;
  
    if (checkbox.Checked == true)
    {
     dt.Rows.Add(dr);
    }
    else if (checkbox.Checked == false)
    {
     int nIndex = dt.Rows.IndexOf(dr);
     dt.Rows.RemoveAt(nIndex);
    }
  
    ViewState.Add("dtTemp", dt);
   }
  }
  </code></pre>