ASP网格视图中文本框的必填字段验证器 [英] Required Field validator for text box in asp grid view

查看:78
本文介绍了ASP网格视图中文本框的必填字段验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含文本框和按钮的asp网格视图.我已经为文本框设置了必填字段验证器,并将必填字段验证器和按钮的验证组设置为相同.
现场验证器显示所有文本框而不是我单击的按钮.是否仍然有基于我单击的按钮显示文本框的验证器?

在此先感谢

I have an asp grid view which contains a text box and button.I have set a required field validator for the text box and set the validation group of required field validator and the button the same.But on clicking the button the required field validator shows up for all the text boxes instead of the button i clicked.Is there anyway to show the validator for text box based on the button i clicked?

Thanks in advance

推荐答案

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
<columns>
<asp:TemplateField>
            <HeaderTemplate >SSSS</HeaderTemplate>
            <itemtemplate><asp:TextBox ID="t1" runat ="server" 
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
            ControlToValidate="t1" ErrorMessage="Enter Value"
            <asp:Button ID="btn1" runat="server" Text ="OK" OnClick ="Button1_Click">
            </itemtemplate>
            

</columns>


在后面的代码中
首先将gridview与您的需求绑定.


in code behind
first bind gridview with your requirement.

protected void Button1_Click(object sender,EventArgs e)
{
}


您需要使用RequiredFieldValidator的ControlToValidate属性来获取或设置要验证的输入控件.您只能验证您想要对其进行字段验证的那些控件.
you need to use ControlToValidate property of RequiredFieldValidator to Gets or sets the input control to validate. you can validate only those control for which you want required field validation.
<asp:RequiredFieldValidator runat="server" id="RFVID" controltovalidate="txtName" errormessage="Please enter value!" />


在这里,您正在验证txtName文本框,以检查RequiredField验证.
看看那里-[RequiredFieldValidator] [多个文本框的RequiredFieldValidator [


here you are validating txtName textbox for checking RequiredField Validation.
Take a look there-[RequiredFieldValidator][^] for more details.

In addition you should navigate given links
RequiredFieldValidator for multiple text boxes[^]


< asp:gridview id =" GridView1"runat =" server "autogenerateeditbutton =" True"autogenerateselectbutton =" True"xmlns:asp ="#unknown>
<列> < asp:templatefield headertext =文本框">
< itemtemplate>
< asp:textbox id ="textbox1" runat ="server" validationgroup ="G1">
< asp:requiredfieldvalidator controltovalidate ="textbox1" runat ="server" errormessage ="*">
文字=错误文字" ValidationGroup ="G1">


< asp:templatefield headertext =文本框">
< itemtemplate>
< asp:textbox id ="textbox2" runat ="server">



< asp:button id ="Button2" runat ="server" text ="Button 1" validationgroup ="G1" xmlns:asp =#unknown">
< asp:button id ="Button3" runat ="server" text ="Button 2" xmlns:asp =#unknown">
<asp:gridview id="GridView1" runat="server" autogenerateeditbutton="True" autogenerateselectbutton="True" xmlns:asp="#unknown">
<columns> <asp:templatefield headertext="text box">
<itemtemplate>
<asp:textbox id="textbox1" runat="server" validationgroup="G1">
<asp:requiredfieldvalidator controltovalidate="textbox1" runat="server" errormessage="*">
Text="error text" ValidationGroup="G1">


<asp:templatefield headertext="text box">
<itemtemplate>
<asp:textbox id="textbox2" runat="server">



<asp:button id="Button2" runat="server" text="Button 1" validationgroup="G1" xmlns:asp="#unknown">
<asp:button id="Button3" runat="server" text="Button 2" xmlns:asp="#unknown">


这篇关于ASP网格视图中文本框的必填字段验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆