Hello Everyone,
I have written a code to insert the dynamically generated textbox value in database. I want to check all the textbox generated dynamically at a time. If no textbox empty then only it should insert textbox value into database. But in my code it is inserting the textbox value if one of the textbox has serial number value. How to resolve this kindly help.
My code is
if (txtQuantity.Text != "")
{
try
{
for (int i = 0; i < quantity; i++)
{
if (Request.Form["Textbox"+i.ToString()].Trim()== "")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Enter Serial Number');", true);
}
else
{
con.Open();
string qryInsertProduct = "insert into Product_Details(GatePassNo,ClientID,Product_name,SerialNo,Status,CheckIN_Date ,Customer_Name, Customer_location, System_Date, [GatePass Status],State, City,S) values('" + GatePassNo + "','" + clientID + "','" + productName + "','" + Request.Form["Textbox" + i.ToString()] + "','" + status + "','" + TextBox1.Text + "','" + ddlCName.SelectedItem.Value + "','" + ddlCLocation.SelectedItem.Value + "','" + Label11.Text + "', 'Open','" + DropDownList1.SelectedItem.Value + "','" + DropDownList2.SelectedItem.Value + "','0')";
SqlCommand comInsertProduct = new SqlCommand(qryInsertProduct, con);
comInsertProduct.ExecuteNonQuery();
con.Close();
gdvProducts.Visible = true;
PopulateGridView();
}
}
}
catch (Exception ex)
{
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}