使用Gridview中的RegularExpressionValidator在文本框下方显示错误消息

时间:2014-05-09 13:14:18

标签: asp.net gridview validation

我正在验证Gridview中的TextBox。当它被假设时显示错误消息,但消息的第一个单词显示在文本框旁边,其余部分显示在文本框下面。如何确保整个邮件位于文本框下方。

这是.aspx代码:

 <asp:GridView ID="MappingGridView" runat="server" AllowSorting="True" AutoGenerateColumns="False" Caption="Enrollment Mapping Information" CaptionAlign="Top" 
    CssClass="grid" HorizontalAlign="Left" ShowFooter="True" AllowPaging="True" PageSize="4" ShowHeaderWhenEmpty="true" OnPageIndexChanging="MappingGridView_PageIndexChanging" 
     OnRowDataBound="MappingGridView_RowDataBound" OnRowCommand="MappingGridView_RowCommand">
    <Columns>
         <asp:TemplateField HeaderText="MappingID" SortExpression="mgvMappingID">
            <ItemTemplate>
                <asp:Label ID="mgvLblMappingID" runat="server" Text='<%# Bind("EnrollmentMappingID") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
 <asp:TemplateField HeaderText="CECityActivityID" SortExpression="mgvCECityActivityID">
            <EditItemTemplate>
                <asp:TextBox ID="mgvEditCECityActivityID" runat="server" Text='<%# Bind("CECityActivityID") %>'></asp:TextBox>
                <asp:RegularExpressionValidator ID="RegExpValEditCECityID" ControlToValidate="mgvEditCECityActivityID" runat="server" 
                     ErrorMessage="Enter 0-9, A-F, and hyphens. Maximum length is 50." ValidationGroup="MappingGrid" ValidationExpression="^[0-9A-Fa-f-]{0,50}$" 
                     Display="Dynamic" CssClass="message-error">
                 </asp:RegularExpressionValidator>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="mgvLblCECityActivityID" runat="server" Text='<%# Bind("CECityActivityID") %>'></asp:Label>
            </ItemTemplate>
             <FooterTemplate>
                <asp:TextBox ID="mgvInsertCECityActivityID" runat="server" Width="90%"></asp:TextBox>
                <asp:RegularExpressionValidator ID="RegExpValCECityID" ControlToValidate="mgvInsertCECityActivityID" runat="server" 
                     ErrorMessage="Enter only 0-9, A-F, and hyphens; maximum length is 50." ValidationGroup="MappingGrid" ValidationExpression="^[0-9A-Fa-f-]{0,50}$" 
                     Display="Dynamic" CssClass="message-error">
                 </asp:RegularExpressionValidator>
            </FooterTemplate>
        </asp:TemplateField>
 </Columns>
 </asp:GridView>

这是显示:

enter image description here

如何让文字完全显示在文本框下方的一行?

谢谢, 格洛丽亚

3 个答案:

答案 0 :(得分:4)

应用CSS类CssClass="display-next"

<asp:RegularExpressionValidator ID="RegExpValCECityID" CssClass="display-next"

然后

.display-next
{
 clear:both;
 display:block;
 float:left;
}

答案 1 :(得分:0)

一种方法是将其放在block元素中:

<p>
    <asp:RegularExpressionValidator ID="RegExpValCECityID" ControlToValidate="mgvInsertCECityActivityID" runat="server" 
         ErrorMessage="Enter only 0-9, A-F, and hyphens; maximum length is 50." ValidationGroup="MappingGrid" ValidationExpression="^[0-9A-Fa-f-]{0,50}$" 
         Display="Dynamic" CssClass="message-error">
     </asp:RegularExpressionValidator>

</p>

另一种方法是添加CssClass,并将其命名为block-validation

.block-validation {
    display: block;
}

您甚至可以修改CssClass的当前message-error

.message-error {
    display: block;
    ...
}

答案 2 :(得分:0)

    。显示,未来     {

    display:block;
    float:inherit;
}

这个css代码可以工作..