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 7985333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:31:25+00:00 2026-06-04T11:31:25+00:00

Question: I’m trying to validate the dropdownlist if the user checked the checkbox as

  • 0

Question:

I’m trying to validate the dropdownlist if the user checked the checkbox as you can see in the screen one.

Problem:

So, how can I validate the checkbox if the user have select all the checkboxes from header?
as you can see the screen two. if I select all the checkboxes then i am looking to fireup the validate as shown in screen one.

output:

screen 1:
enter image description here

screen 2

enter image description here

//aspx

<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  HeaderText="Reject">
         <HeaderTemplate >
            Reject<br />
            <asp:CheckBox ID="checkboxall"  runat="server" />

              <asp:DropDownList ID="drpPaymentMethod_header" runat="server">
                    <asp:ListItem Value="-1">Please select reason</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>

        </HeaderTemplate>
            <ItemTemplate>
                <asp:CheckBox ID="checkbox1" CssClass="selectreject"  runat="server" />
                <asp:DropDownList ID="drpPaymentMethod" runat="server">
                    <asp:ListItem Value="-1">Please select reason</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" ForeColor="Red" SetFocusOnError="true"
                    Enabled="false" Display="dynamic" runat="server" ErrorMessage="Please select reason"></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");
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                CheckBox checkboxall = e.Row.FindControl("checkboxall") as CheckBox;
                //how to get the reference here ( rfv ?????????)
                //checkboxall.Attributes.Add("onclick", "UpdateValidatorAll('" + checkboxall.ClientID + "','" + drpPaymentMethod.ClientID + "','" + rfv.ClientID + "');");

            } 
        }

//js

$(document).ready(function () {

            var checkbox1 = "#<%=gv.ClientID%> input[id*='checkbox1']:checkbox";
            var checkboxall = $("input[id$='checkboxall']");

            $(checkboxall).click(function () {  
                if (checkboxall.is(':checked')) {
                    $('.selectreject > input').attr("checked", checkboxall.attr("checked"));   
                }
                else {
                    $('.selectreject > input').attr("checked", false); 
                }

            });

        }); 

        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);
        }

        function UpdateValidatorAll(....) // i havent write the code for this function (select All checkbox)
  • 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-04T11:31:27+00:00Added an answer on June 4, 2026 at 11:31 am

    try this:
    ASPX:

    <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>
                <HeaderTemplate>
                    Reject<br />
                    <asp:CheckBox ID="checkboxall" runat="server" />
                    <asp:DropDownList ID="drpPaymentMethod_header" runat="server">
                        <asp:ListItem Value="-1">Please select reason</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>
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:CheckBox ID="checkbox1" runat="server" />
                    <asp:DropDownList ID="drpPaymentMethod" CssClass="gridDropDown" 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" CssClass="gridRfv" 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>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    

    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");
            }
    
            if (e.Row.RowType == DataControlRowType.Header)
            {
                CheckBox checkboxall = e.Row.FindControl("checkboxall") as CheckBox;
    
                checkboxall.Attributes.Add("onclick", "UpdateValidatorAll('" + checkboxall.ClientID + "');");
    
            }
        }
    

    JavaScript:

    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/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);
        }
    
        function UpdateValidatorAll(chkID) {
            //enabling the validator only if the checkbox is checked
            var enableValidator = !$("#" + chkID).is(":checked");
    
            $('.gridDropDown').each(function (index) {
                if (enableValidator)
                    $(this).removeAttr('disabled');
                else
                    $(this).attr('disabled', 'disabled');
            });
    
            $('.gridRfv').each(function (index) {
                var cont = $(this).get();
                ValidatorEnable(cont[0], enableValidator);
    
            });
    
        }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question: How can I detect which rows have lastModifiedDate < boundary at 30s/minute <
Question: Can anyone please provide a full code example that shows how one does
Question: How can I give a new user almost all privileges, but still keep
Question I have two compilers on my hardware C++ and C89 I'm thinking about
Question slightly in the abstract... We have a situation where we have a struct
Question 1) I have a control to which I add an attribute from the
Question: How can I document Ruby code using Doxygen? Disclaimer: I know ruby already
Question is quite simple. Let's say I have an URL config with line: url(r'^models/(?P<model_group_id>[0-9]+)/(?P<page>\d+)/$',
Question: I want to test an if statement in PostgreSQL: IF (SELECT COUNT(*) FROM
Question: Can I override default functions in Javascript? Background: After figuring out that I

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.