Hi all,
I have a gridview consisting for each row of three DropDownList and one textbox and one checkbox.
When all the dropdownlists of the entire gridview have been completed, I must select the checkbox and validate the data using the code below.
However, if at least one of the values in the DropDownList contains the "KO" value for that row, it is mandatory to fill in the text field.
I used this code but it doesn't work because even when only one row of the grid has been compilated by the DropDownLists that row is validated.
Instead I would like the validation to be performed only when all the rows and all the Dropdownlist of the grid are all filled in.
Can you help me?
private void MTH (ImageButton imgbtn)
{
if (imgbtn != null)
{
foreach (GridViewRow row in gvProducts.Rows)
{
CheckBox chk = (CheckBox)row.FindControl("chkRow");
string ddl_1 = ((DropDownList)row.FindControl("ddl_1")).Text;
string ddl_2 = ((DropDownList)row.FindControl("ddl_2")).Text;
string ddl_3 = ((DropDownList)row.FindControl("ddl_3")).Text;
string txt = ((TextBox)row.FindControl("txt")).Text;
if (ddl_1.ToString().ToUpper() == "KO" || ddl_2.ToString().ToUpper() == "KO" ||
ddl_3.ToString().ToUpper() == "KO") && String.IsNullOrEmpty(txt.ToString()))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert",
"alert('0 - KO');", true);
}
else
{
if (chk.Checked && !String.IsNullOrEmpty(ddl_1.ToString()) &&
!String.IsNullOrEmpty(ddl_2.ToString()) && !String.IsNullOrEmpty(ddl_3.ToString()))
{
using (MySqlConnection myConnectionString =
new MySqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
{
using (MySqlCommand cmd =
new MySqlCommand("sp_chkRow", myConnectionString))
{
cmd.CommandTimeout = 2147483;
cmd.Connection.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Clear();
cmd.Parameters.Add(new MySqlParameter("@spSqlQuery", MySqlDbType.VarChar));
cmd.Parameters["@spSqlQuery"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
cmd.Connection.Close();
string spSqlQuery = string.Empty;
spSqlQuery = cmd.Parameters["@spSqlQuery"].Value.ToString();
Response.Write(spSqlQuery.ToString() + "<br />");
}
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert",
"alert('1 - KO');", true);
}
}
}
}
}