Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to validate the grid when a checkbox and textbox is present

how to validate the grid when a checkbox and textbox is present

Scheduled Pinned Locked Moved ASP.NET
javascriptcsstutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lakshmichawala
    wrote on last edited by
    #1

    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.

    A V 2 Replies Last reply
    0
    • L lakshmichawala

      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.

      A Offline
      A Offline
      avi_dadi2002
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • L lakshmichawala

        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.

        V Offline
        V Offline
        vimal_yet
        wrote on last edited by
        #3

        check this link http://msdn.microsoft.com/en-us/library/ms972948.aspx[^]

        If U Get Errors U Will Learn If U Don't Get Errors U Have Learnt

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups