简体   繁体   English

如何在嵌套的GridView控件中访问TextBox和标签

[英]How to access TextBox and label in a Nested GridView Control

I am looking for a Jquery validation Script that checks the values in my textbox and displays error message in bold red. 我正在寻找一个Jquery验证脚本,该脚本检查我的文本框中的值并以红色粗体显示错误消息。 The values should be within a range like my range is between 10 and 40. If it is greater than 40 or less than 10 then the label becomes red and the message says "The value you entered is 6, it should be between 10 and 40. My textbox and labels are in the nested GridView. It should check value for each textbox. Also if the number is out of range for any textbox the save button should be disabled. and should only be enabled if all textbox values are in range.Below is my code: 值应在10到40之间的范围内。如果该值大于40或小于10,则标签将变为红色,并显示消息“您输入的值为6,应在10到40之间我的文本框和标签位于嵌套的GridView中,它应检查每个文本框的值;如果该数字超出任何文本框的范围,则应禁用保存按钮;并且仅在所有文本框值均在范围内时才应启用。下面是我的代码:

<asp:GridView ID="GridView2" AutoGenerateColumns="False" runat="server"
    ShowHeader="False" Style="width: 100%; border-width: 0px;">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>

                <asp:GridView AutoGenerateColumns="false" ID="GridView2" runat="server"
                    ShowHeader="true" GridLines="None">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:TextBox ID="txtAmount" runat="server" ItemStyle-HorizontalAlign="center"></asp:TextBox>
                                <asp:Label ID="lblMessage" runat="server" ItemStyle-HorizontalAlign="center"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>

            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />

You could use the aspnet Validators, such as the RangeValidator 您可以使用aspnet验证程序,例如RangeValidator

<ItemTemplate>
    <asp:TextBox ID="txtAmount" runat="server" ItemStyle-HorizontalAlign="center"></asp:TextBox>

    <asp:RangeValidator ID="RangeValidator1" runat="server" 
        ErrorMessage="The value you entered is incorrect, it should be between 10 and 40" 
        ControlToValidate="txtAmount" Display="Dynamic" MinimumValue="10" MaximumValue="40"
        Type="Integer">
    </asp:RangeValidator>

    <asp:Label ID="lblMessage" runat="server" ItemStyle-HorizontalAlign="center"></asp:Label>
</ItemTemplate>

Perhaps you have to use a ValidationGroup , depending on your needs. 也许您必须根据需要使用ValidationGroup

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM