Pregunta

I have a gridview with two BoundFields for DATE_RANGE_FROM and DATE_RANGE_TO. I want to use a CompareValidator to make sure DATE_RANGE_TO would not contain date that is earlier than DATE_RANGE_FROM when the user edits them. Can I use gridview boundfields as controltovalidate and controltocompare?

<asp:GridView ... >
   <Columns>
      <asp:boundfield datafield="DATE_RANGE_FROM" convertemptystringtonull="true" headertext="Period Covered From" />
      <asp:boundfield datafield="DATE_RANGE_TO" convertemptystringtonull="true" headertext="Period Covered To" />
   </Columns>
</asp:GridView>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="DATE_RANGE_TO" ControlToCompare="DATE_RANGE_FROM" Operator="GreaterThanEqual" Type="Date" ErrorMessage="Period Covered To should NOT be earlier than Period Covered From."></asp:CompareValidator>
¿Fue útil?

Solución

Try converting these columns to Template columns and then use this validator inside those templates, placing it outside the grid will never work as the ID's for the columns change for each row..

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top