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. validate Dropdownlist inside gridview using javascript

validate Dropdownlist inside gridview using javascript

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-netquestion
5 Posts 4 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.
  • D Offline
    D Offline
    deepthy p m 0
    wrote on last edited by
    #1

    I use ASP.NET + C# In My form I have a Gridview inside gridview i use a dropdown list In dropdownlist it contain --Select-- and other items I want to add a validation to this dropdownlist so that the user must choose an item other than --Select-- I need to validate using javascript .How can i do that

    P H 2 Replies Last reply
    0
    • D deepthy p m 0

      I use ASP.NET + C# In My form I have a Gridview inside gridview i use a dropdown list In dropdownlist it contain --Select-- and other items I want to add a validation to this dropdownlist so that the user must choose an item other than --Select-- I need to validate using javascript .How can i do that

      P Offline
      P Offline
      padmanabhan N
      wrote on last edited by
      #2

      //if u have given selectedindex for your dropdownlist --select-- as 0 function error() { if ( document.getElementById('..._dropdownlist').selectedIndex = "0") alert('select atleast one'); } //but it will more easy if u provide a required field validator.

      Padmanabhan

      D 1 Reply Last reply
      0
      • P padmanabhan N

        //if u have given selectedindex for your dropdownlist --select-- as 0 function error() { if ( document.getElementById('..._dropdownlist').selectedIndex = "0") alert('select atleast one'); } //but it will more easy if u provide a required field validator.

        Padmanabhan

        D Offline
        D Offline
        deepthy p m 0
        wrote on last edited by
        #3

        i will not work bcs i place the dropdownlist inside the gridview .

        S 1 Reply Last reply
        0
        • D deepthy p m 0

          i will not work bcs i place the dropdownlist inside the gridview .

          S Offline
          S Offline
          sidbaruah
          wrote on last edited by
          #4

          Add a javascript function through attributes.add in cs for(int i=0;i< gridview.rows.count;i++) { DropDownList ddl = (DropDownList)gridview.rows[i].cells[cellid].findcontrol('id'); ddl.attributes.add("onchange","return func("+ddl.clientid+");"); } Send the row id from the cs file function func(ddl) { //Do the validation in javascript } Hope that helps!!

          I was born dumb!! :laugh:Programming made me laugh:laugh:!!! --sid--

          1 Reply Last reply
          0
          • D deepthy p m 0

            I use ASP.NET + C# In My form I have a Gridview inside gridview i use a dropdown list In dropdownlist it contain --Select-- and other items I want to add a validation to this dropdownlist so that the user must choose an item other than --Select-- I need to validate using javascript .How can i do that

            H Offline
            H Offline
            harish mehra
            wrote on last edited by
            #5

            Please check yhe beolw script code function check(id) { var n=document.getElementById("grd"); var namecontrol=id.name; var myval=new Array(); var Arr=new Array(); myval=namecontrol.split("$") var rowindex=myval[1]; var j=rowindex if (document.getElementById("grd_"+j+"_ddl").value == '-- SELECT --') { alert("Please Select Sb Code.."); document.getElementById("grd_"+j+"_ddl").focus(); return false; } }

            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