Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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..?
Posted

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.
 
Share this answer
 
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:
XML
<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. :)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900