Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>credit goes to ahaliav fox http://stackoverflow.com/questions/10566599/how-to-control-asp-net-validator-controls-client-side-validation gridview: &lt;asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" OnRowDataBound="gv_RowDataBound"&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="ID" ControlStyle-Width="250px" HeaderText="ID" SortExpression="ID" /&gt; &lt;asp:BoundField DataField="FirstName" ControlStyle-Width="250px" HeaderText="FirstName" SortExpression="FirstName" /&gt; &lt;asp:BoundField DataField="LastName" ControlStyle-Width="250px" HeaderText="LastName" SortExpression="LastName" /&gt; &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="checkbox1" runat="server" /&gt; &lt;asp:DropDownList ID="drpPaymentMethod" runat="server"&gt; &lt;asp:ListItem Value="-1"&gt;----&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="0"&gt;Month&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="1"&gt;At End&lt;/asp:ListItem&gt; &lt;asp:ListItem Value="2"&gt;At Travel&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;asp:RequiredFieldValidator ID="rfv" InitialValue="-1" ControlToValidate="drpPaymentMethod" Enabled="false" Display="Static" runat="server" ErrorMessage="RequiredFieldValidator"&gt;&lt;/asp:RequiredFieldValidator&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Value"&gt; &lt;ItemTemplate&gt; &lt;asp:TextBox ID="txt_Value" runat="server" Width="58px" Text="0"&gt;&lt;/asp:TextBox&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; 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); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload