how to validate the grid when a checkbox and textbox is present
-
iam having a grid where there is one checkbox and one text box in each row now how can i validate using javascript if the check box is checked then textbox of that particular row of the grid should not be left blank .this should happen when submit button is clicked.
-
iam having a grid where there is one checkbox and one text box in each row now how can i validate using javascript if the check box is checked then textbox of that particular row of the grid should not be left blank .this should happen when submit button is clicked.
Load the grid with values in page load with isnot postback Like if (!IsPostBack) { SqlConnection cn = new SqlConnection("Data Source=; Initial Catalog=;user ID=sa"); SqlCommand cmd = new SqlCommand("Select top 5 [Group] from customerlist WHERE [Group] is not null", cn); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } after that in button click event add this code bool status = false; for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[1].FindControl("chk"); TextBox txt = (TextBox)GridView1.Rows[i].Cells[2].FindControl("txt"); if (chk.Checked == true) if (txt.Text.Trim() == "") { status = true; //return; } } if (status == true) { Response.Write("TextValue Sholdn't be blank"); } else { Response.Write("Success"); } Send me if u've any doubt.It will work
-
iam having a grid where there is one checkbox and one text box in each row now how can i validate using javascript if the check box is checked then textbox of that particular row of the grid should not be left blank .this should happen when submit button is clicked.