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 wono = ""; int prsl = 0, qty = 0; string unit = ""; 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++) { wono = TextBox1.Text; //accsl = int.Parse(Label2.Text); if (j == 1) prsl = Convert.ToInt32(GridView1.Rows[i].Cells[j].Text); //if (j == 2) qty = Convert.ToInt32(GridView1.Rows[i].Cells[j].Text);
// my problem is that i can not insert data from gridview textbox.
TextBox txt = (TextBox)row.FindControl("txtQty"); //int ll = int.Parse(txt.Text); int k = int.Parse(txt.Text); if (j == 2) qty =Convert.ToInt32(GridView1.Rows[i].Cells[k].Text); if (j ==3 ) price = Convert.ToDecimal(GridView1.Rows[i].Cells[j].Text); if (j ==4) unit = GridView1.Rows[i].Cells[j].Text; } InsertData(wono,prsl, qty, price, unit); ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Success fully added (PR...)');", true);
} } TextBox1.Enabled = true; Button2.Visible = false; } }
please any body helpm me best regurds. thanks