EditTemplate 中的 RegularExpressionValidator

RegularExpressionValidator in EditTemplate

提问人:Mounica 提问时间:7/25/2023 最后编辑:Tiny WangMounica 更新时间:7/28/2023 访问量:33

问:

我有abc.aspx如下

<asp:content id="Content" ContentPlaceHolderID="cpContent" runat="server">

        <style type="text/css">
                .textbox-align-center {
                  display: flex;
                  text-align: center;
                }
        </style>
    
<asp:Panel ID="pnlPresentation" runat="server" Width="105%" ScrollBars="Auto">
        <asp:GridView ID="gridPresentation" runat="server" AutoGenerateColumns="False" >
    

        
        <asp:TemplateField HeaderText="abc" ItemStyle-HorizontalAlign="Center">
                            <EditItemTemplate>
                                <asp:RegularExpressionValidator ID="regexValidatorABC" runat="server" ControlToValidate="txtABC_Edit"
                                    ValidationExpression="^[A-Z]{1,3}\d{0,4}$" 
                                    ErrorMessage="Please enter a valid input with minimum length 3, maximum length 7 (with 1-3 Capitals letters followed by 4 digits), and no spaces."
                                    ForeColor="Red" Font-Size="Small" CssClass="textbox-align-center">
                                </asp:RegularExpressionValidator>                        
                                <asp:TextBox ID="txtABC_Edit" runat="server" Text='<%# Eval("[26_ABC]") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblABC" runat="server" AutoPostBack="true" OnTextChanged="txtABC_TextChanged" 
                                    Text='<%# Eval("[26_ABC]")%>' Width="100%" />
                            </ItemTemplate>
         </asp:TemplateField>
        </asp:GridView>
                
</asp:Panel> 
</asp:content>

当我打开 EditTemplate 时,具有验证器的 TexBox 未居中对齐。

如何将其对准中心?

asp.net 验证 GridView

评论


答:

0赞 Mounica 7/28/2023 #1

我在 RegularExpressionValidator 中删除了 CssClass,并添加了 div 并将 EditTemplate 和 TextBox 放入其中。

更新后的代码在这里,

<asp:content id="Content" ContentPlaceHolderID="cpContent" runat="server">

        <style type="text/css">
                .textbox-align-center {
                  display: flex;
                  justify-content: center;
                  align-items: center;
                  text-align: center;
                }
        </style>
    
<asp:Panel ID="pnlPresentation" runat="server" Width="105%" ScrollBars="Auto">
   <asp:GridView ID="gridPresentation" runat="server" AutoGenerateColumns="False" >
        <asp:TemplateField HeaderText="abc" ItemStyle-HorizontalAlign="Center">
        <EditItemTemplate>
           <div class="textbox-align-center">
             <asp:RegularExpressionValidator ID="regexValidatorABC" runat="server" ControlToValidate="txtABC_Edit"
                                    ValidationExpression="^[A-Z]{1,3}\d{0,4}$" 
                                    ErrorMessage="Please enter a valid input with minimum length 3, maximum length 7 (with 1-3 Capitals letters followed by 4 digits), and no spaces."
                                    ForeColor="Red" Font-Size="Small">
                                </asp:RegularExpressionValidator>                        
                                <asp:TextBox ID="txtABC_Edit" runat="server" Text='<%# Eval("[26_ABC]") %>'></asp:TextBox>
</div>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblABC" runat="server" AutoPostBack="true" OnTextChanged="txtABC_TextChanged" 
                                    Text='<%# Eval("[26_ABC]")%>' Width="100%" />
                            </ItemTemplate>
         </asp:TemplateField>
        </asp:GridView>
                
</asp:Panel> 
</asp:content>