Client side Validation for DropDownList value in GridView

Client side Validation for DropDownList value in GridView to check if any value is selected or not.

Add following code on 'OnClientClick' event of the asp.net button
OnClientClick="javascript:return validateGridComboBox();

Javascript Function:
function validateGridComboBox() 
    {
            var flag = false;
            var dropdowns = new Array(); //Create array to hold all the dropdown lists.
            var gridview = document.getElementById('<%=GridView1.ClientID %>'); //GridView1 is the id of ur gridview.
            
            dropdowns = gridview.getElementsByTagName('select'); //Get all dropdown lists contained in GridView1.            
            for (var i = 0; i < dropdowns.length; i++) {
                if (dropdowns.item(i).value != '0') //If dropdown has no selected value
                {                   
                    flag = true;
                    break; //break the loop as there is no need to check further.
                }
            }
            
            if (flag == false) 
            {
                alert('Require atleast one record to have dropdown value selected.');
                return flag;
            }                      
    }  

Comments

Popular posts from this blog

WCF WSDL location address Issue resolved when hosted over HTTPS with basicHTTPBinding

Yellow Background issue in Word to PDF conversion

Gmail tricks - create unlimited siblings of your Gmail address