Hello developers,
I want to compare textbox value with data table created in the session. If the textbox value matches with data table column item id, it should not allow to re enter that item on button click.
Screenshot
What I have tried:
protected void AddInGrid(object sender, EventArgs e)
{
messagelabel.Text = "";
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTabele"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0 & txtquantity.Text != "0" & checkstock()==true)
{
for (int i = 1; i <= 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";
}
}