Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
how can i add javascript validation to Textbox in GridView item template column.....plz tel me any one its very urgent...
Posted
Comments
Karthik_Mahalingam 17-Dec-13 4:54am    
Which validation you want to apply ??

1 solution

hello friend i have you can modified this code to applied you validation logic. i have added simple validation like if the textbox value is more then 4 character then it will displayed in red or it will green.

ASP.NET
<asp:gridview id="grdView" runat="server" autogeneratecolumns="false" xmlns:asp="#unknown">
            <columns>
                <asp:templatefield headertext="Validation">
                    <itemtemplate>
                        <asp:textbox id="txtValidation" runat="server"></asp:textbox>
                    </itemtemplate>
                </asp:templatefield>
            </columns>
        </asp:gridview>


JavaScript
<script type="text/javascript">
        $(document).ready(function () {
            $('[id*="txtValidation"]').blur(function () {
                if ($(this).val().length > 4) {
                    $(this).css("color", "red");
                }
                else {
                    $(this).css("color", "green");
                }
            });
        });
    </script>
 
Share this answer
 

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