protected void Button2_Click(object sender, EventArgs e) { if (TextBox1.Text == "") { ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('PR no can not be blank');", true); } else { string unit = "", prno = ""; int qty = 0, accsl = 0; string remark = ""; decimal price = 0; for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { GridViewRow row = GridView1.Rows[i]; CheckBox Chbox = (CheckBox)row.FindControl("chb1"); if (Chbox.Checked == true) { select++; } }
if (select == 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('select checkbox for insert)');", true); return; }
for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { GridViewRow row = GridView1.Rows[i]; CheckBox Chbox = (CheckBox)row.FindControl("chb1"); if (Chbox.Checked == true) { for (int j = 1; j < GridView1.Rows[i].Cells.Count; j++) {
prno = TextBox1.Text; //accsl = int.Parse(Label2.Text); if (j == 1) qty = Convert.ToInt32(GridView1.Rows[i].Cells[j].Text); if (j == 2) price = Convert.ToDecimal(GridView1.Rows[i].Cells[j].Text); if (j == 3) unit = GridView1.Rows[i].Cells[j].Text; if (j == 4) remark = GridView1.Rows[i].Cells[j].Text; if (j == 5) accsl = Convert.ToInt32(GridView1.Rows[i].Cells[j].Text); } InsertData(prno, qty,price, unit, remark, accsl); ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Success fully added (PR...)');", true);
} } TextBox1.Enabled = true; Button2.Visible = false; } }