Note that there are some explanatory texts on larger screens.

plurals
  1. POValidation for checked items in gridview
    primarykey
    data
    text
    <p>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.</p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="grvStyle" Width="100%" OnRowDataBound="GridView1_RowDataBound"&gt; &lt;EmptyDataTemplate&gt; &lt;asp:Label ID="lblnorow" runat="server" Text="Record not Found"&gt;&lt;/asp:Label&gt; &lt;/EmptyDataTemplate&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText="SrNo." ItemStyle-Width="30px" ItemStyle-HorizontalAlign="Center"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="lblsrno" runat="server"&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField="Dates" HeaderText="Dates"&gt; &lt;HeaderStyle HorizontalAlign="Center"&gt;&lt;/HeaderStyle&gt; &lt;ItemStyle HorizontalAlign="Center"&gt;&lt;/ItemStyle&gt; &lt;/asp:BoundField&gt; &lt;asp:TemplateField HeaderText="Registration Closing Date"&gt; &lt;ItemTemplate&gt; &lt;asp:TextBox ID="txtCloseDate" runat="server" CssClass="datepicker"&gt;&lt;/asp:TextBox&gt; &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ValidationGroup="VGrpSelect" ControlToValidate="txtCloseDate" ErrorMessage="Registration Closing Date is required" Display="none" SetFocusOnError="True"&gt; &lt;/asp:RequiredFieldValidator&gt; &lt;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"&gt; &lt;/asp:RegularExpressionValidator&gt; &lt;/ItemTemplate&gt; &lt;HeaderStyle HorizontalAlign="Center" /&gt; &lt;ItemStyle HorizontalAlign="Center" /&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="No of Pax"&gt; &lt;ItemTemplate&gt; &lt;asp:TextBox ID="txtNoOfPax" runat="server" Width="50"&gt;&lt;/asp:TextBox&gt; &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ValidationGroup="VGrpSelect" ControlToValidate="txtNoOfPax" ErrorMessage="No of Pax is required" Display="none" SetFocusOnError="True"&gt; &lt;/asp:RequiredFieldValidator&gt; &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ValidationGroup="VGrpSelect" SetFocusOnError="True" Display="None" ErrorMessage="No of Pax must have Numeric value" ControlToValidate="txtNoOfPax" ValidationExpression="\d*"&gt; &lt;/asp:RegularExpressionValidator&gt; &lt;/ItemTemplate&gt; &lt;HeaderStyle HorizontalAlign="Center" /&gt; &lt;ItemStyle HorizontalAlign="Center" /&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="60px" ItemStyle-HorizontalAlign="Center"&gt; &lt;HeaderTemplate&gt; Select&lt;asp:CheckBox ID="chkHeaderSelect" runat="server" onclick="SetCheckBox(this)" /&gt; &lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="chkSelect" runat="server" onclick="CheckCheckBox()" /&gt; &lt;asp:HiddenField ID="hidf" runat="server" Value='&lt;%# Eval("Dates") %&gt;' /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;RowStyle CssClass="data-row" /&gt; &lt;AlternatingRowStyle CssClass="alt-data-row" /&gt; &lt;PagerStyle HorizontalAlign="Right" ForeColor="Black" /&gt; &lt;/asp:GridView&gt; &lt;script type="text/javascript"&gt; function GVal(chk, req) { if (chk.Checked == true) { req.Enabled = true; } else { req.Enabled = false; } } &lt;/script&gt; </code></pre> <p>In rowdatabound event of gridview</p> <pre><code>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 + ");"); } } </code></pre> <p>I have done something like this but it shows validation for all rows.</p>
    singulars
    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.
 

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