title: ASP.net, Compare textbox value with data table column value
body: <p>I want to compare the textbox value with a data table created in the session.
  If the textbox value matches with the data table column item id, it should not allow to re enter that item on button click.</p>
  
  <p><img src="https://i.stack.imgur.com/jFdJH.png" alt="Screen Shot"></p>
  
  <pre><code>protected void AddInGrid(object sender, EventArgs e)
  {
      messagelabel.Text = "";
      DataTable dtCurrentTable = (DataTable)ViewState["CurrentTabele"];
      DataRow drCurrentRow = null;
  
      if (dtCurrentTable.Rows.Count &gt; 0 &amp; txtquantity.Text != "0" &amp; checkstock()==true)
      {
          for (int i = 1; i &lt;= dtCurrentTable.Rows.Count; i++)
          {
              //Creating new row and assigning values
              drCurrentRow = dtCurrentTable.NewRow();
              drCurrentRow["Item Id"] = Convert.ToInt32(txtid.Text);
              drCurrentRow["Item Name"] = txtname.Text;
              drCurrentRow["Price"] = Convert.ToInt32(txtprice.Text);
              drCurrentRow["Quantity"] = Convert.ToInt32(txtquantity.Text);
              drCurrentRow["Item Total"] = Convert.ToInt32(txttotalitemprice.Text);
          }
  
          //Removing initial blank row
          if (dtCurrentTable.Rows[0][0].ToString() == "")
          {
              dtCurrentTable.Rows[0].Delete();
              dtCurrentTable.AcceptChanges();
          }
  
          //Added New Record to the DataTable
          dtCurrentTable.Rows.Add(drCurrentRow);
          //storing DataTable to ViewState
          ViewState["CurrentTabele"] = dtCurrentTable;
          //binding Gridview with New Row
          gvGridview1.DataSource = dtCurrentTable;
          gvGridview1.DataBind();
      }
      else if (checkstock() == false)
      {
          messagelabel.Text = "Stock Not Enough";
      }
  }
  </code></pre>