2017-06-30 42 views
0

我收到一條錯誤消息,說明CheckBox1未被聲明,但它肯定是在gridview之前。背景是用戶正在批准gridview中的記錄。如果記錄未被批准,則複選框未被選中。因爲它沒有被批准,我還想要求用戶解釋原因的評論。 只有當複選框未選中時,才需要註釋。聲明CheckBox顯示爲未驗證器中的未聲明

我試過轉移驗證器周圍,但我沒有任何運氣。有什麼我失蹤?對於asp.net仍然很新穎。後端是vb.net。以下是評論欄。如果需要更多,請讓我知道。

的錯誤:

'CheckBox1' is not declared. It may be inaccessible due to its protection level.

驗證碼:

<asp:TemplateField HeaderText="Comment"> 
    <ItemTemplate> 
     <asp:TextBox ID="Comment" MaxLength="200" runat="server" Width="500px" Text='<%# Eval("Comment") %>'></asp:TextBox> 
     <asp:RegularExpressionValidator 
      Display = "Dynamic" 
      ControlToValidate = "Comment" 
      ID="RegularExpressionValidator" 
      ValidationExpression = "^[a-zA-Z0-9'@&#.\s]{2,200}$" 
      runat="server" 
      ForeColor="red" 
      ErrorMessage="!"> 
     </asp:RegularExpressionValidator> 
     <%If CheckBox1.Checked = "False" then%> 
      <asp:RequiredFieldValidator id="RequiredFieldValidator" runat="server" 
       ControlToValidate="Comment" 
       ErrorMessage="*Required" 
       ForeColor="Red"> 
      </asp:RequiredFieldValidator> 
     <%Else%> 
     <%End If%> 
    </ItemTemplate> 
</asp:TemplateField> 
+1

您無法訪問GridView模板中的其他控件。 – VDWWD

回答

0

不能容易禁用和啓用的RequiredFieldValidator基於邏輯的客戶端更不用說那些控件是在GridView中。

我的建議是不要爲RequiredFieldValidator使用該特定場景。然後讓用戶發佈表單,然後在服務器端驗證這些輸入。

+0

我想要做的是在ItemTemplate中設置一個CustomValidator,以調用vb.net端的一個SubView,GridView將逐行檢查複選框和註釋文本框的狀態。這似乎是一個可行的解決方案? – grichmer

+0

大多數CustomValidator在服務器端進行驗證,除非您創建一個可以驗證客戶端和服務器端的驗證;這不是一件容易的事。如果你想,你可以試試。 – Win