Click here to Skip to main content
12,509,612 members (50,727 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
<asp:GridView ID="gvAttributes" runat="server"
              AutoGenerateColumns="false" EnableModelValidation="True"
              CssClass="GridViewStyle" onrowdatabound="gvAttributes_RowDataBound">
  <Columns>
    <asp:TemplateField HeaderText="Select">
      <ItemTemplate>
        <asp:CheckBox ID="cbxAttributescheck" runat="server" Text=''
        <%# Eval("AttributeName") %> AutoPostBack="true" OnCheckedChanged="cbxAttributescheck_CheckedChanged"/>
protected void cbxAttributescheck_CheckedChanged(object sender, EventArgs e)
{
    CheckBox cbx = (CheckBox)sender;
    string CurrentCbxId = ((CheckBox)sender).ClientID;
    foreach (GridViewRow Row in gvAttributes.Rows)
    {
        if (((CheckBox)Row.FindControl("cbxAttributescheck")).ClientID.Equals(CurrentCbxId) && cbx.Checked)
        {
            RequiredFieldValidator rfvAttributeType = (RequiredFieldValidator)Row.FindControl("rfvAttributeType");
            rfvAttributeType.Enabled = true;
        }
    }
}
I took grid view as above.
I want to enable the required field validator for drop down, when check box is checked.
I want to do this server side not through JavaScript.
I tried but unable to work out. I tried to enable the validator, when check box checked else it will be disabled.
I need assistance on this.
Posted 6-Feb-13 22:44pm
v2
Comments
Avik Ghosh22 7-Feb-13 4:57am
   
<asp:DropDownList ID="ddlAttributesDataType" runat="server" required>


"required" is required field validator in HTML5 .... try this...
Rajasekhar_Raj 7-Feb-13 5:08am
   
Not in Html5 We need in Asp.net
Avik Ghosh22 7-Feb-13 5:12am
   
ok.
Tadit Dash 7-Feb-13 6:36am
   
Why not to do it in jQuery?
That will be easier and will eliminate extra burden for server as it is calling server code for check change.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

a validator needs ValidationGroup property to have some value to work, assign a Validation Group (say 'validate') to check box, drop down and the button on which you want to fire validation. Give it a try and post your outcome.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100