title: Remove duplicate value in gridview rows
body: <p>I have seen this question asked and answered before but none of the answers helped me. I want that when I insert a value from the textbox by pressing a button, if that value already exists in the gridview to be removed or not inserted at all.</p>
  
  <p>My code:</p>
  
  <pre><code>protected void Buton1_Click(object sender, EventArgs e)
  {
      DataTable dt = null;
  
      if (Session["GridData"] == null)
      {
          dt = new DataTable();
          DataColumn dc = new DataColumn("Name");
          dt.Columns.Add(dc);
      }
      else
      {
          dt = Session["GridData"] as DataTable;
      }
  
      DataRow dr = dt.NewRow();
      dr["Name"] = TextBox1.Text;
      dt.Rows.Add(dr);
      dt.AcceptChanges();
      GridView1.DataSource = dt;
      GridView1.DataBind();
      Session["GridData"] = dt;
  }
  </code></pre>