Geeks With Blogs


Microsoft MVP


Moderator at CodeASP.NET

Quiz Master

free counters
Free counters
Added on January 19,2012

Follow Me @vmsdurano

A bit About Me

The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.

Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

In my previous post here I have demonstrated how to add dynamic rows in Gridview with a combination of TextBox and DropDownList. Just in case you need to validate empty TextBox values  before adding a new row to the GridView then here's a JavaScript function that you can use for validation: 

function ValidateEmptyValue() { 
    var gv = document.getElementById("<%= Gridview1.ClientID %>"); 
    var tb = gv.getElementsByTagName("input"); 
    for (var i = 0; i < tb.length; i++) { 
        if (tb[i].type == "text") { 
            if (tb[i].value < 1) { 
                alert("Field cannot be blank!"); 
                return false; 
    return true; 


Then at OnClientClick event of the Add New Button, you can simply call the JavaScript function above like below: 

<asp:Button ID="ButtonAdd" runat="server" Text="Add New Row"
                           OnClientClick="return ValidateEmptyValue();" />  

That's it! I hope you'll find this post useful! 


Posted on Thursday, August 5, 2010 4:10 PM ASP.NET , JavaScript , GridView | Back to top

Comments on this post: Adding Dynamic Rows in GridView with TextBox and DropDownList - Validation

# re: Adding Dynamic Rows in GridView with TextBox and DropDownList - Validation
Requesting Gravatar...
Works great, except if you have Javascript off. Server side validation is a must for any serious application.
Left by Aaron on May 22, 2012 2:08 AM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: