When I add any validators to any template type inside of a gridview it seems that the validators change the height, width and alignment of the cell/column. I can strip out all formatting [remove the stylesheet and any other attributes] and when I add the validators to the template the formatting changes – implicating the validators. I am very new to .net – how do I prevent any formatting impact from validators? I would think they would have zero impact!
Thanks!
below is one example of a column:
<asp:TemplateField HeaderText="Paid" SortExpression="PaidPrice" ControlStyle-Width="50px" ItemStyle-HorizontalAlign="center">
<EditItemTemplate>
<asp:TextBox ID="PaidPrice" runat="server" Text='<%# Eval("PaidPrice","{0:f}") %>' ></asp:TextBox>
<asp:CompareValidator ID="CompareValidator2" Runat="server" ControlToValidate="PaidPrice" Operator="DataTypeCheck" Type="Currency"
ErrorMessage="You must provide a valid currency value for the Paid Price." >*</asp:CompareValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblPaidPrice" runat="server" Text='<%# Eval("PaidPrice","{0:c}") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
You didn’t really specify what is changing on the formatting, but based on your code I have a good guess. I’d bet the width of the columns is wider than you want and showing white space.
If this is the case, this may be the cure:
Set the Display property of the vlaidators to “Dynamic”. Then they will only take up space if there is a validaiton error.
The default value of this property is “Static”, which causes it to take up the same amount of space, whether the message is visible or not.