Hey there,
I have a datatable dtValues which takes values from ddl,label,textbox on a button(Add) click.this button adds these values to the grid. I have used data table dtValues as datasource to gridview.
Now when these values are filled in data table/grid,On button click Add
it takes the previous values again and again into the grid.
My code for btnAdd is :-
protected void btnAdd_Click(object sender, EventArgs e)
{
if (ddlSearchItems.SelectedIndex > 0)
{
DataRow drValues = dtValues.NewRow();
drValues["Id"] = ddlSearchItems.SelectedItem.Value;
drValues["Item"] = ddlSearchItems.SelectedItem.Text;
drValues["Rate"] = lblActualPrice.Text;
drValues["Qty"] = txtQuantity.Text;
drValues["Amount"] = Convert.ToInt32(lblActualPrice.Text) * Convert.ToInt32(txtQuantity.Text);
dtValues.Rows.Add(drValues);
dtValues.AcceptChanges();
gvOrders.DataSource = dtValues;
gvOrders.DataBind();
gvOrders.Visible = true;
}
}
The values stays in the grid until they are submitted by a button click(btnSubmit) on which i resets the data table.
How can i avoid that user is not able to put the same previous order in database on btnAdd_click?
I am using this to save the records into database--
private void InsertOrder(int productId, int quantity)
{
objSqlHelper.InsertOrderInDB(txtName.Text, txtAddress.Text, Convert.ToInt32(txtPhone.Text), DateTime.Now, productId, quantity);
}
;