1

我有 GridView:

<asp:GridView ID="MyGridView" runat="server" ShowFooter="true"
                                AutoGenerateColumns="False" Visible="True">
<Columns>
<asp:BoundField DataField="id" ItemStyle-HorizontalAlign="center"/>
<asp:BoundField DataField="fullName"  />
<asp:TemplateField HeaderText="situation>">
<ItemTemplate>
  <asp:DropDownList ID="dl_situation" runat="server">
   </asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField>
 <ItemTemplate>
         <asp:TextBox ID="tbNr" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>  
<asp:TemplateField HeaderText="Data">
<ItemTemplate>
 <asp:TextBox ID="tbDate" runat="server"></asp:TextBox>
 </asp:RequiredFieldValidator>
 </ItemTemplate>
</asp:TemplateField>     
</Columns>
</asp:GridView>

它工作正常,但是当我为 id="tbDate" 的文本框添加 RegularrExpressionValidator 时,mygrid 不起作用此正则表达式必须接受格式为“dd.MM.yyyy”的日期时间

 <asp:GridView ID="MyGridView" runat="server" ShowFooter="true"
                                AutoGenerateColumns="False" Visible="True">
<Columns>
<asp:BoundField DataField="id" ItemStyle-HorizontalAlign="center"/>
<asp:BoundField DataField="fullName"  />
<asp:TemplateField HeaderText="situation>">
<ItemTemplate>
  <asp:DropDownList ID="dl_situation" runat="server">
   </asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField>
 <ItemTemplate>
         <asp:TextBox ID="tbNr" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>  
<asp:TemplateField HeaderText="Data">
<ItemTemplate>
 <asp:TextBox ID="tbDate" runat="server"></asp:TextBox>
 <asp:RegularExpressionValidator ID="RegularCert" runat="server" 
      ControlToValidate="tbDate" ErrorMessage="Incorect Data" 
 ValidationExpression=
"(0[1-9]|[12][0-9]|3[01])[-.](0[1-9]|1[012])[-.](19|20)[0-9]{2}" 
      Display="Dynamic"></asp:RegularExpressionValidator>
     <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
      ErrorMessage="*" ControlToValidate="tbDate">
   </asp:RequiredFieldValidator>
 </ItemTemplate>
</asp:TemplateField>     
</Columns>
</asp:GridView>
4

4 回答 4

2

我认为您在 ControlToValidate 属性中输入了“tbData”而不是“tbDate”

<asp:RegularExpressionValidator ID="RegularCert" runat="server" 
  ControlToValidate="tbDate" ErrorMessage="Incorect Data"   ValidationExpression= "(0[1-9]|[12][0-9]|3[01])[-.](0[1-9]|1[012])[-.](19|20)[0-9]{2}" 
  Display="Dynamic"></asp:RegularExpressionValidator>
于 2012-08-17T10:03:20.220 回答
2

我改成for ,ClientIDMode开始工作PredictableTextBoxRegularExpressionValidatorRequiredFieldValidator

于 2012-08-20T13:10:08.233 回答
1

更改ControlToValidate="tbData"ControlToValidate="tbDate"_<asp:RegularExpressionValidator

于 2012-08-17T10:06:27.360 回答
0

您是否尝试过将其放置在<asp:RegularExpressionValidator ...>内部, <ItemTemplate>
<asp:TextBox ID="tbDate" runat="server"></asp:TextBox>
</ItemTemplate> 如果它未能通过正则表达式验证,您还需要指示一些要显示的文本

实际上哈莉所说的很可能是答案哈

于 2012-08-17T10:01:52.563 回答