I have a Webform in ASP.Net(C#) using SQL SERVER 2005, In this I was looking to Delete multiple Rows in GridView using Checkbox,I found many example while searching, Its deleting properly but I also want, while selecting checkbox,Deleted Quantity should store in Stock table. Suppose i want to delete some hardware from the system, while selecting systemName in dropdownlist it display all the hardware install in system in gridview, while selecting in checkbox and press delete button it should delete from the gridview and insert quantity in the stock. So for that, what Should I do. Can anyvody will help me to resolve this problem.
I have used Some code shown below
protected void BtnRemove_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in dgvRemoveHware.Rows)
{
CheckBox cBox = (CheckBox)row.FindControl("CheckBox1");
if (cBox.Checked)
{
int ConferenceId11 = Convert.ToInt32(dgvRemoveHware.DataKeys[row.RowIndex].Values[0]);
int CatId11 = Convert.ToInt32(dgvRemoveHware.DataKeys[row.RowIndex].Values[1]);
int PId11 = Convert.ToInt32(dgvRemoveHware.DataKeys[row.RowIndex].Values[2]);
int Qty11 = Convert.ToInt32(dgvRemoveHware.DataKeys[row.RowIndex].Values[3]);
ConnectionStr();
con.Open();
SqlCommand cmd = new SqlCommand("Delete from SystemConfiguration where ConfId='" + ConferenceId11 + "'",con);
cmd.ExecuteNonQuery();
SqlCommand cmdA = new SqlCommand("Select CatId,PId,Qty from SystemConfiguration where ConfId='" + ConferenceId11 + "'", con);
cmdA.ExecuteNonQuery();
con.Close();
con.Close();
BtnRemove.Visible = true;
BtnCancel.Visible = true;
}
}
BindHardware1();
}
Note:- Better if will get the code,
In stock table i have column CatId, PId, Qty