When checkbox is checked and user enter any wrong value then I am checking in database and based on result value checkbox remaining checked not to update data.
In my case I have updated multiple row with single update button so I need to validate each row in loop. If any row fire custom validation then want to exit loop from there.
But custom validator should display message that is not appearing on the screen and when it is exit for then it will not execute remaining grid row.
I want to run all the row and whichever row has error (result <> "CanChange") those row want to keep as in edit mode.
<asp:TemplateField HeaderText="Qty" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" HeaderStyle-Font-Bold="true" HeaderStyle-Width="60px">
<ItemTemplate>
<asp:Label runat="server" ID="lbloqua" Text='<%# Eval("oqua", "{0:F2}") %>'></asp:Label>
<asp:TextBox ID="txtoqua" OnTextChanged="CheckPOQty" AutoPostBack="true" Style="padding-right: 4px; padding-left: 4px; white-space: nowrap; min-width: 60px; text-align: right" CssClass="form-control" runat="server" Text='<%# Eval("oqua") %>' Visible="false"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ID="vl_gw_txtoqua" SetFocusOnError="true" Display="Dynamic" CssClass="help-block" ControlToValidate="txtoqua" ValidationGroup="gv_items" ForeColor="#ff3636" Font-Size="10px" Style="letter-spacing: 1px; margin-left: 0px;"><i class="fa fa-exclamation-triangle"></i> Enter Quantity. </asp:RequiredFieldValidator>
<asp:CustomValidator ID="custoqua" runat="server" Display="Dynamic" SetFocusOnError="true" ControlToValidate="txtoqua" ForeColor="Red" Text="Cannot exceed value !!" ValidationGroup="gv_items"></asp:CustomValidator>
</ItemTemplate>
</asp:TemplateField>
Protected Sub CheckPOQty(ByVal sender As Object, ByVal e As EventArgs)
Try
For Each row As GridViewRow In gv_poitem.Rows
If row.RowType = DataControlRowType.DataRow Then
Dim isChecked As Boolean = row.Cells(1).Controls.OfType(Of CheckBox)().FirstOrDefault().Checked
Dim txtreqno As String = row.Cells(2).Controls.OfType(Of TextBox)().FirstOrDefault().Text
If isChecked And txtreqno <> "" Then
Dim nwpoqtyVal As TextBox = CType(sender, TextBox)
Dim reqno_srno As String = row.Cells(2).Controls.OfType(Of TextBox)().FirstOrDefault().Text
Dim splitval() As String = Convert.ToString(reqno_srno).Split("/")
Dim reqno As String = splitval(0)
Dim srno As Integer = Convert.ToInt16(splitval(1))
Dim posno As Integer = row.Cells(0).Controls.OfType(Of Label)().FirstOrDefault().Text
Dim orno As Integer = txtorno.Text
Dim nwpoqtyx As Decimal = row.Cells(7).Controls.OfType(Of TextBox)().FirstOrDefault().Text
Dim oldpoqty As Integer = row.Cells(7).Controls.OfType(Of Label)().FirstOrDefault().Text
Dim custoquax As CustomValidator = CType(row.Cells(7).FindControl("custoqua"), CustomValidator)
Dim item As String = row.Cells(3).Controls.OfType(Of TextBox)().FirstOrDefault().Text
Dim nwpoqty As Decimal = crud.CheckPOQtyValidationbyItem(reqno, orno, item, nwpoqtyx, oldpoqty)
Dim result As String = crud.CheckPOQtyValidation(reqno, srno, posno, orno, nwpoqty)
If result = "CanChange" Then
lblnewqty.Visible = False
' nwpoqtyVal.BorderColor = System.Drawing.ColorTranslator.FromHtml("#cccccc")
nwpoqtyVal.Focus()
custoquax.IsValid = True
Else
lblnewqty.Visible = True
' nwpoqtyVal.BorderColor = System.Drawing.ColorTranslator.FromHtml("#ff3636")
nwpoqtyVal.Focus()
custoquax.IsValid = False
End If
End If
End If
Next
Catch ex As Exception
Me.log.LogError(ex)
End Try
End Sub