我想将文本框值与会话中创建的数据表进行比较。 如果文本框值与数据表列项ID匹配,则不应允许在按钮单击时重新输入该项。
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";
}
}