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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:17:02+00:00 2026-06-04T07:17:02+00:00

Below is the output of my page after it runs the below code: I’m

  • 0

Below is the output of my page after it runs the below code:

I’m using ValidatorEnable client side validation in my situation (if you know better way to do that, let me know.)

My question is:

Ihave a gridview with checkbox and a dropdownlist next to each other as shown in the screen shot.

So, if the user checked on the checkbox it enabled the dropdownlist to select from.
if the user clicks on submit button it validates and ask the user to select any options from the dropdownlist.

Problem:

But the problem is: its validating for all the rows instead of the one i have clicked.

How can i enforce to validate that particular row the user checked on the checkbox?

enter image description here

    <asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" OnRowDataBound="gv_RowDataBound"
            EnableModelValidation="True">
            <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="ddl_PaymentMethod" 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="requiredDDL" runat="server" ControlToValidate="ddl_PaymentMethod"
                            ErrorMessage="Please select" InitialValue="-1" Display="Dynamic"></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>


protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
 if (e.Row.RowType == DataControlRowType.DataRow)
 {
    CheckBox checkbox1 = (CheckBox)e.Row.FindControl("checkbox1");
    DropDownList ddl_PaymentMethod = (DropDownList)e.Row.FindControl("ddl_PaymentMethod");
    ddl_PaymentMethod.Attributes.Add("disabled", "disabled");

   checkbox1.Attributes.Add("onclick", "javascript:EnableCheckBox('" + ddl_PaymentMethod.ClientID + "','" + checkbox1.ClientID + "')"); 
 }
}

function EnableCheckBox(ddl, chk) {

  var ddl_PaymentMethod = document.getElementById(ddl);
  var _chkbox = document.getElementById(chk);
  if (_chkbox.checked) {
      ddl_PaymentMethod.disabled = false;
      validateCheckBox(ddl_PaymentMethod, true);
   }
   else { 
      ddl_PaymentMethod.disabled = true;
      validateCheckBox(ddl_PaymentMethod, false);
   }
}

function validateCheckBox(ddl, state) {
    ValidatorEnable(document.getElementById(ddl.id, state));             
}
  • 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-04T07:17:03+00:00Added an answer on June 4, 2026 at 7:17 am

    got it working for you…
    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

I'm having some problems trying to get the code below to output the data
In the code below i was expecting another output! : #include <stdio.h> #include <stdlib.h>
In the code below, the output is : S1S2. Why do we get the
I'm using toLocalizedTime to output a date, as below <span tal:content=python:here.toLocalisedTime(date.get('start_date'))/> This outputs eg.
any idea how i can get the code below to produce this output? 1
I have the page below, everything works fine... Except that after I click the
My LINQ query is not producing the expected output below. Basically, it's the sum
The snippet below is generating weird output: for s in servers: vo = ss.getServerVO(s)
Im not sure how to output MySQL data into formats below. (eg: timelist, usersex,
Ive a HABTM relationship where the output is like below, what i would like

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.