ASP.net,将文本框值与数据表列值进行比较

时间:2017-07-13 16:43:36

标签: c# asp.net sql-server datatable

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

Screen Shot

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";
    }
}

0 个答案:

没有答案