You must Sign In to post a response.
  • Category: ASP.NET

    How to Validate 2 dropdownlist values inside gridview using javascript

    Hello All

    My requirement is I need to validate 2 dropdown list values inside gridview if it comes to edit mode contains edit item template.

    scenario like I had dropdown 1 ,dropdown 2 it select same value i need to show validation message using javascript function all dropdown are inside the grid view control when its comes to edit item template .

    kindly hep me to unblock this issue.

  • #769516
    Hi Anand,

    Using the below steps, you can achieve your result,

    1. Add onclientclick with a javascript function with the current object as below,
    <asp:button id="btnSave" runat="server" text="Save" onclientclick="javascript:return ValidateFields(this);"/>

    2. Whenever you click this button, it will call the javascript function. In this function, you have to validate all of your grid view control fields here. Finally, if there is no error then return false otherwise return true.

    3. If you don't mention the return statement then it calls your codebehind function

    In javascript, you can find your gridview control as follows,
    1. While calling the function it pass the current button control object as a parameter
    2. $(CurrentObj).id using this code you can get the id of that button
    3. Now, in same row all other control id will be same only the name needs to change. Below, is the example of the control name,
    <asp:dropdownlist id="dropdown1"/>
    <asp:dropdownlist id="dropdown2"/>
    <asp:button id="btnSave" runat="server" text="Save" onclientclick="javascript:return ValidateFields(this);"/>

    In javascript function you will get the btnSave ID something like this,

    Now, you can just replace the id "btnSave" to "dropdownlist1" you can get the value of the dropdown list control.

    Like this, you can get all the fields and you can validate it.

    Let me know if you have any questions.

    V.M. Damodharan
    "Your talent will be worthless, when you have fear and tension."

  • Sign In to post your comments