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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:43:04+00:00 2026-06-16T06:43:04+00:00

I have Gridview in which two textboxes and one checkbox in one row. and

  • 0

I have Gridview in which two textboxes and one checkbox in one row.
and i want required field validation for both textboxes when that checkbox is checked otherwise i dont want validation.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="grvStyle"
    Width="100%" OnRowDataBound="GridView1_RowDataBound">
    <EmptyDataTemplate>
        <asp:Label ID="lblnorow" runat="server" Text="Record not Found"></asp:Label>
    </EmptyDataTemplate>
    <Columns>
        <asp:TemplateField HeaderText="SrNo." ItemStyle-Width="30px" ItemStyle-HorizontalAlign="Center">
            <ItemTemplate>
                <asp:Label ID="lblsrno" runat="server"></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Dates" HeaderText="Dates">
            <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
            <ItemStyle HorizontalAlign="Center"></ItemStyle>
        </asp:BoundField>
        <asp:TemplateField HeaderText="Registration Closing Date">
            <ItemTemplate>
                <asp:TextBox ID="txtCloseDate" runat="server" CssClass="datepicker"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ValidationGroup="VGrpSelect"
                    ControlToValidate="txtCloseDate" ErrorMessage="Registration Closing Date is required"
                    Display="none" SetFocusOnError="True">
                </asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtCloseDate"
                    Display="None" ErrorMessage="Invalid Registration Closing Date Format" SetFocusOnError="True"
                    ValidationGroup="VGrpSelect" ValidationExpression="([1-9]|0[1-9]|[12][0-9]|3[01])[- /.]([1-9]|0[1-9]|1[012])[- /.](19|20|30)\d\d">
                </asp:RegularExpressionValidator>
            </ItemTemplate>
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="No of Pax">
            <ItemTemplate>
                <asp:TextBox ID="txtNoOfPax" runat="server" Width="50"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ValidationGroup="VGrpSelect"
                    ControlToValidate="txtNoOfPax" ErrorMessage="No of Pax is required"
                    Display="none" SetFocusOnError="True">
                </asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ValidationGroup="VGrpSelect"
                    SetFocusOnError="True" Display="None" ErrorMessage="No of Pax must have Numeric value"
                    ControlToValidate="txtNoOfPax" ValidationExpression="\d*">
                </asp:RegularExpressionValidator>
            </ItemTemplate>
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>
        <asp:TemplateField HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="60px"
            ItemStyle-HorizontalAlign="Center">
            <HeaderTemplate>
                Select<asp:CheckBox ID="chkHeaderSelect" runat="server" onclick="SetCheckBox(this)" />
            </HeaderTemplate>
            <ItemTemplate>
                <asp:CheckBox ID="chkSelect" runat="server" onclick="CheckCheckBox()" />
                <asp:HiddenField ID="hidf" runat="server" Value='<%# Eval("Dates") %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <RowStyle CssClass="data-row" />
    <AlternatingRowStyle CssClass="alt-data-row" />
    <PagerStyle HorizontalAlign="Right" ForeColor="Black" />
</asp:GridView>

<script type="text/javascript">
    function GVal(chk, req) {
        if (chk.Checked == true) {
            req.Enabled = true;
        }
        else {
            req.Enabled = false;
        }
    }
</script>

In rowdatabound event of gridview

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Label lblSrNo = (Label)e.Row.FindControl("lblSrNo");
        int srno = e.Row.DataItemIndex + 1;
        lblSrNo.Text = srno.ToString();

        CheckBox chkSelect = (CheckBox)e.Row.FindControl("chkSelect");
        TextBox txtCloseDate = (TextBox)e.Row.FindControl("txtCloseDate");
        RequiredFieldValidator required = (RequiredFieldValidator)e.Row.FindControl("RequiredFieldValidator10");
        chkSelect.Attributes.Add("onclick", "javascript:GVal(" + chkSelect.ClientID + "," + required.ClientID + ");");
    }
}

I have done something like this but it shows validation for all rows.

  • 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-16T06:43:05+00:00Added an answer on June 16, 2026 at 6:43 am
     function GVal(chk, req) {
    
            ValidatorEnable(document.getElementById(req),document.getElementById(chk).checked);
    
    }
    

    More details you can find here [ASP.NET Validation in Depth]: http://msdn.microsoft.com/en-us/library/aa479045.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview in which i have two textboxes. The senarios is such
I have Two Labels such as FixedTotal and TotalPercent, One GridView which has One
I have an ASP.NET GridView control with two asp:CommandField columns that are both using
I have two GridView s in my Page which contains multiple items. One is
I have a GridView which is databound to an XML Datasource. For one of
Have a gridview control which will show X amount of rows. I want to
I have a GridView in which each row has a custom view. The grid
I have a GridView to which I bind a dataTable that I manually created.
For example, Lets say that I have a gridview column which has important controls,
i have a GridView (selectable) in which I want to generate a dynamic GridView

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.