Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7936559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:15:13+00:00 2026-06-03T22:15:13+00:00

edit: var dropDownControls = $(‘#<%=GridView1.ClientID %> select option:selected’); var checkbox = $…….checkbox ….. for(index

  • 0

edit:

var dropDownControls = $('#<%=GridView1.ClientID %> select option:selected');
var checkbox = $.......checkbox ..... 
  for(index = 0; index < dropDownControls.length; index++)
  {
      if (checkbox.checked) //my code gets exaclty what checkbox i checked
      {
      if(dropDownControls[index].selectedIndex == 0)
      {
          flag = false;
          break;
      }
      }
  }

the above code works

i have my button outside the gridivew and i am trying to validate the dropdownlist which is inside the gridivew.

<asp:Button ID="btn" runat="server" Text="Submit" OnClick="btn_Click"  CausesValidation="true"/>


<asp:GridView ID="GVInputMapping" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
                             EnableModelValidation="True" onrowdatabound="GVInputMapping_RowDataBound">
<Columns>
<asp:BoundField DataField="Name" ControlStyle-Width="250px" HeaderText="Name" SortExpression="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox id="checkbox1" runat="server"/>
<asp:DropDownList runat="server" ID="ddldetail">
<asp:ListItem Selected="True" Value="0">Select me</asp:ListItem>
<asp:ListItem Value="1">abc</asp:ListItem>
<asp:ListItem Value="2">GHt</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="requiredDDL" runat="server" 
              ControlToValidate="ddldetail" ErrorMessage="Please select" InitialValue="Select me"  Display="Dynamic"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:15:14+00:00Added an answer on June 3, 2026 at 10:15 pm
    credit goes to ahaliav fox
    
    http://stackoverflow.com/questions/10566599/how-to-control-asp-net-validator-controls-client-side-validation
    
    
     gridview:
    
        <asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"  OnRowDataBound="gv_RowDataBound">
                <Columns>
                    <asp:BoundField DataField="ID" ControlStyle-Width="250px" HeaderText="ID" SortExpression="ID" />
                    <asp:BoundField DataField="FirstName" ControlStyle-Width="250px" HeaderText="FirstName"
                        SortExpression="FirstName" />
                    <asp:BoundField DataField="LastName" ControlStyle-Width="250px" HeaderText="LastName"
                        SortExpression="LastName" />
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:CheckBox ID="checkbox1" runat="server" />
                            <asp:DropDownList ID="drpPaymentMethod" runat="server">
                                        <asp:ListItem Value="-1">----</asp:ListItem>
                                        <asp:ListItem Value="0">Month</asp:ListItem>
                                        <asp:ListItem Value="1">At End</asp:ListItem>
                                        <asp:ListItem Value="2">At Travel</asp:ListItem>
                                    </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="rfv" InitialValue="-1" ControlToValidate="drpPaymentMethod" Enabled="false" Display="Static" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
    
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Value">
                        <ItemTemplate>
                            <asp:TextBox ID="txt_Value" runat="server" Width="58px" Text="0"></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
    
    CS:
    
        protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox checkbox1 = e.Row.FindControl("checkbox1") as CheckBox;
                    RequiredFieldValidator rfv = e.Row.FindControl("rfv") as RequiredFieldValidator;
                    DropDownList drpPaymentMethod = (DropDownList)e.Row.FindControl("drpPaymentMethod");
                    // you can just pass "this" instead of "myDiv.ClientID" and get the ID from the DOM element
                    checkbox1.Attributes.Add("onclick", "UpdateValidator('" + checkbox1.ClientID + "','" + drpPaymentMethod.ClientID + "','" + rfv.ClientID + "');");
                    if (!checkbox1.Checked)
                        drpPaymentMethod.Attributes.Add("disabled", "disabled");
                }
            }
    
    javascript:
    
        function UpdateValidator(chkID, drpID, validatorid) {
                //enabling the validator only if the checkbox is checked
                var enableValidator = $("#" + chkID).is(":checked");
    
                if (enableValidator)
                    $('#' + drpID).removeAttr('disabled');
                else
                    $('#' + drpID).attr('disabled', 'disabled');
    
                var vv = $('#' + validatorid).val();
    
                ValidatorEnable(document.getElementById(validatorid), enableValidator);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT : Per Slaks $j('#banner-content img').each(function() { var link = $j('#page-tabs li a.' +
Possible Duplicate: C# 'var' keyword versus explicitly defined variables EDIT: For those who are
Edit: We can close. Isn't truly asynchronous, non-blocking javascript impossible? var PATH = require
http://jsbin.com/eyeqer/2/edit var x = document.evaluate('//p/following-sibling::text()', document, null, XPathResult.ANY_TYPE, null); var theTitle = x.iterateNext(); while
Please see my code here http://jsbin.com/ijoxa3/edit var drawHorizondalLine = function(x1,y1,x2,y2, color) { var width
I've implemented a jqgrid with inline edit: var lastSel; jQuery(document).ready(function () { jQuery(#list).jqGrid({ url:
Possible Duplicate: Difference between calling self.var vs var Edit : actually, i did not
I have two Edit User Action methods. The first populates a checkbox correctly with
The cake php validation 'isUnique' gives error on edit var $validate = array( 'name'
Edit: 2 var elems = $(#D li).toArray(); elems.sort(function(a, b) { var adate = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.