Friday, September 21, 2012

ASP.NET : Validate In place edit GridView using jQuery.

ASP.NET : Validate In place edit GridView using jQuery.

This very easy demo will show you how to validate TextBox in GridView by using jQuery.
Demo Code show below.

The Result

Update Cancel 0 *
Edit 1 Dow jones
Edit 2 Million Dollar
Edit 3 Bank of America

1 : Add modify Template in GridView set OnClientClick="return validateGridView();"

        <asp:TemplateField ShowHeader="False">
                <asp:LinkButton ID="lbtEdit" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
                <asp:LinkButton ID="lbtUpdate" runat="server" CausesValidation="True" CommandName="Update" Text="Update" OnClientClick="return validateGridView();"></asp:LinkButton>
                <asp:LinkButton ID="lbtCancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>

2 : Add Alert Label near Require Text.

        <asp:Label ID="lblReqCustomerName" runat="server" ForeColor="Red" Text="*" style="display:none;" CssClass="lblReqCustomerName"></asp:Label>

3 : Add Javascript Validate Function.

    function validateGridView() {
        if ($(".txtCustomerName").val() == "") {
            return false;
        else {
            return true;

DownloadDemo Here

Don't hesitate to contact me zomdev.

No comments:

Post a Comment