在行视图中验证gridview中的文本框(使用必需的字段验证器和自定义验证器) [英] validate the textbox in a gridview on row wise(using required field validator and custom validator)

查看:61
本文介绍了在行视图中验证gridview中的文本框(使用必需的字段验证器和自定义验证器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

heyy ..



在我的网格中。我想在项目模板中验证文本框。我想验证我要编辑的特定行中的文本框。剩余验证是禁用...任何想法..?

解决方案

您可以在您的使用OnRowCommand asp定义gridview,在文本框定义中指定commandargument,然后在eventhandler中使用GridViewCommandEventArgs.CommandArgument。


您好,您可以使用EditItemTemplate中的验证来验证要更新的值网格视图的特定行。所有类型的Asp.net验证器控件都可以在EditItemTemplate中使用,我使用RegularExpressionValidator给出了示例。当用户尝试更新网格视图行中的文本框值时,验证将起作用。网格视图的定义如下:

 <   asp:GridView     ID   =   MyGridview    runat  < span class =code-keyword> =  server    AutoGenerateColumns   =  false    OnRowEditing   =  MyGridview_RowEditing  

< span class =code-attribute> OnRowUpdating = MyGridview_RowUpdating >
< >
< asp:TemplateField >
< ItemTemplate >
< span class =code-keyword>< asp:TextBox ID = txtItem < span class =code-attribute> runat = server ReadOnly = true / >
< / ItemTemplate >
< EditItemTemplate > ;
< asp:TextBox ID = txtedit runat = server / >
< asp:RegularExpressionValidator ID = regEx runat = server ErrorMessage = 提供字母数字。

ControlToValidate = txtedit ValidationExpression = ^ [a-zA-Z0-9 _] *


ValidationGroup = updateGrp > < / asp:RegularExpressionValidator >
< / EditItemTemplate >
< / asp:TemplateField >
< asp:TemplateField >
< ItemTemplate >
< < span class =code-leadattribute> asp:LinkBut​​ton ID = lnkEdit 文字 = 编辑 runat = server < span class =code-attribute> CommandName = 编辑 CausesValidation = false / >
< span class =code-keyword>< / ItemTemplate >
< EditItemTemplate >
< asp:LinkBut​​ton < span class =code-attribute> ID = lnkUpdate 文字 = 更新 runat = server CommandName = < span class =code-keyword>更新

< span class =code-attribute> CausesValidation = True ValidationGroup = updateGrp / >
< / EditItemTemplate > ;
< / asp:TemplateField >
< /列 >
< / asp:GridView >





确保正确设置CausesValidation和ValidationGroup属性。 :)


heyy..

In my grid.I want validate textboxes in item template . i want to validate textbox in specific row that I want to edit..Remaining validation is disable ...Any idea..?

解决方案

You can use OnRowCommand in your asp definition of the gridview, specify the commandargument in your textbox definition and then in the eventhandler use GridViewCommandEventArgs.CommandArgument.


Hi, You can use validations in EditItemTemplate for validating the value to be updated in a particular row of the grid view. All kind of Asp.net validator controls can be used in EditItemTemplate, I am giving example using RegularExpressionValidator. Here the validation will work when user try to update the textbox value in grid-view row. The definition of grid-view would look like:

<asp:GridView ID="MyGridview" runat="server" AutoGenerateColumns="false" OnRowEditing="MyGridview_RowEditing"

        OnRowUpdating="MyGridview_RowUpdating">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:TextBox ID="txtItem" runat="server" ReadOnly="true" />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtedit" runat="server" />
                    <asp:RegularExpressionValidator ID="regEx" runat="server" ErrorMessage="Provide alphanumeric."

                        ControlToValidate="txtedit" ValidationExpression="^[a-zA-Z0-9_]*


" ValidationGroup="updateGrp"></asp:RegularExpressionValidator> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="lnkEdit" Text="Edit" runat="server" CommandName="Edit" CausesValidation="false" /> </ItemTemplate> <EditItemTemplate> <asp:LinkButton ID="lnkUpdate" Text="Update" runat="server" CommandName="Update" CausesValidation="True" ValidationGroup="updateGrp" /> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>



Make sure you set the "CausesValidation" and "ValidationGroup" properties properly. :)


这篇关于在行视图中验证gridview中的文本框(使用必需的字段验证器和自定义验证器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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