Bootstrap

asp.net WebForm GridView高级应用

一、请做验证,请输入1到20万之间的数值;最多带2位小数

<asp:TemplateField HeaderText="月度限额">
    <ItemTemplate>
        <%# Eval("monthlyLimit") %>
    </ItemTemplate>
    <EditItemTemplate>
        <asp:TextBox ID="txtMonthlyLimit" Width="80" runat="server" Text='<%# Bind("monthlyLimit") %>' CssClass="form-control" />
        <asp:RequiredFieldValidator ID="rfvMonthlyLimit" runat="server"
            ControlToValidate="txtMonthlyLimit" ErrorMessage="月度限额是必输项"
            CssClass="text-danger" Display="Dynamic" />
        <asp:RegularExpressionValidator ID="revMonthlyLimit" runat="server"
            ControlToValidate="txtMonthlyLimit" ErrorMessage="请输入1到200000之间的数值,最多2位小数"
            ValidationExpression="^(200000|[1-9][0-9]{0,4}(\.[0-9]{1,2})?|[1-9](\.[0-9]{1,2})?)$" CssClass="text-danger" Display="Dynamic" />
    </EditItemTemplate>
    <ItemStyle Width="80px" />
</asp:TemplateField>

二、验证整数的范围是15~100

<asp:TemplateField HeaderText="最小年龄">
    <ItemTemplate>
        <%# Eval("minAge") %>
    </ItemTemplate>
    <EditItemTemplate>
        <asp:TextBox ID="txtMinAge" Width="80" runat="server" Text='<%# Bind("minAge") %>' CssClass="form-control" />
        <asp:RequiredFieldValidator ID="rfvMinAge" runat="server"
            ControlToValidate="txtMinAge" ErrorMessage="最小年龄是必输项"
            CssClass="text-danger" Display="Dynamic" />
        <asp:RegularExpressionValidator ID="revMinAge" runat="server"
            ControlToValidate="txtMinAge" ErrorMessage="请输入15到100之间的整数"
            ValidationExpression="^(1[5-9]|[2-9][0-9]|100)$" CssClass="text-danger" Display="Dynamic" />
    </EditItemTemplate>
    <ItemStyle Width="80px" />
</asp:TemplateField>

<asp:TemplateField HeaderText="最大年龄">
    <ItemTemplate>
        <%# Eval("maxAge") %>
    </ItemTemplate>
    <EditItemTemplate>
        <asp:TextBox ID="txtMaxAge" Width="80" runat="server" Text='<%# Bind("maxAge") %>' CssClass="form-control" />
        <asp:RequiredFieldValidator ID="rfvMaxAge" runat="server"
            ControlToValidate="txtMaxAge" ErrorMessage="最大年龄是必输项"
            CssClass="text-danger" Display="Dynamic" />
        <asp:RegularExpressionValidator ID="revMaxAge" runat="server"
            ControlToValidate="txtMaxAge" ErrorMessage="请输入15到100之间的整数"
            ValidationExpression="^(1[5-9]|[2-9][0-9]|100)$" CssClass="text-danger" Display="Dynamic" />
    </EditItemTemplate>
    <ItemStyle Width="80px" />
</asp:TemplateField>

三、行内编辑

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowUpdating="GridView1_RowUpdating">
    <Columns>      

        <asp:TemplateField HeaderText="最小年龄">
            <ItemTemplate>
                <%# Eval("minAge") %>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="txtMinAge" Width="80" runat="server" Text='<%# Bind("minAge") %>' CssClass="form-control" />
            </EditItemTemplate>
            <ItemStyle Width="80px" />
        </asp:TemplateField>

        <asp:TemplateField HeaderText="最大年龄">
            <ItemTemplate>
                <%# Eval("maxAge") %>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="txtMaxAge" Width="80" runat="server" Text='<%# Bind("maxAge") %>' CssClass="form-control" />
            </EditItemTemplate>
            <ItemStyle Width="80px" />
        </asp:TemplateField>
    </Columns>
</asp:GridView>

;