aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Get Validate Textbox Controls Inside Gridview using JavaScript in

Dec 29, 2014

Here I will explain how to get or validate textbox controls inside of gridview using JavaScript or validate gridview footer controls (textbox, dropdownlist, checkbox, radio button etc..) values in JavaScript.

To get or validate textbox controls inside of gridview using JavaScript we need to write the code like as shown below

Syntax to Get or Validate Gridview Controls in JavaScript

<script type="text/javascript">
function GetGridFooterRowvalues() {
var fuid = document.getElementById('<%=((TextBox)gvUserInfo.FooterRow.FindControl("txtUserId")).ClientID %>');
if (fuid.value!= '') {
alert('UserId:' + fuid.value)
alert'Please enter userid')
If you want see it in complete example open your aspx page and write the following code

<html xmlns="">
<head id="Head1" runat="server">
<title>get or validate textbox controls inside gridview using javascript</title>
<script type="text/javascript">
function GetGridFooterRowvalues()
var fuid = document.getElementById('<%=(gvUserInfo.FooterRow.FindControl("txtUserId")).ClientID %>');
var funame = document.getElementById('<%=(gvUserInfo.FooterRow.FindControl("txtUserName")).ClientID %>');
var fueducation = document.getElementById('<%=(gvUserInfo.FooterRow.FindControl("txtEducation")).ClientID %>');
if (fuid.value != '' && funame.value != '' && fueducation.value != '') {
alert('UserId:' + fuid.value + ';UserName:' + funame.value + ';Education:' + fueducation.value)
alert("Please enter all the values")
<form id="form1" runat="server">
<asp:GridView ID="gvUserInfo" runat="server" AutoGenerateColumns="false" ShowFooter="true">
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
<asp:TemplateField HeaderText="UserId">
<asp:Label id="lblUserid" runat="server"  Text='<%# Eval("UserId") %>' />
<asp:TextBox ID="txtUserId" runat="server" />
<asp:TemplateField HeaderText="UserName">
<asp:Label id="lblUsername" runat="server" Text='<%# Eval("UserName") %>'/>
<asp:TextBox ID="txtUserName" runat="server" />
<asp:TemplateField HeaderText="Education">
<asp:Label id="lblEducation" runat="server" Text='<%# Eval("Education") %>'/>
<asp:TextBox ID="txtEducation" runat="server" />
<asp:Button ID="btnGet" Text="Get Footer Values" runat="server" OnClientClick="GetGridFooterRowvalues()" />
After that write the following code in code behind

C# Code

using System;
using System.Data;

public partial class Default3 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            DataTable dt = new DataTable();
            dt.Columns.Add("UserId", typeof(Int32));
            dt.Columns.Add("UserName", typeof(string));
            dt.Columns.Add("Education", typeof(string));
            dt.Rows.Add(1, "Suresh Dasari", "B.Tech");
            dt.Rows.Add(2, "Rohini Dasari", "Msc");
            dt.Rows.Add(3, "Madhav Sai", "MS");
            dt.Rows.Add(4, "Praveen", "B.Tech");
            dt.Rows.Add(6, "Sateesh", "MD");
            dt.Rows.Add(7, "Mahesh Dasari", "B.Tech");
            dt.Rows.Add(8, "Mahendra", "CA");
            gvUserInfo.DataSource = dt;

Imports System.Data
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim dt As New DataTable()
            dt.Columns.Add("UserId", GetType(Int32))
            dt.Columns.Add("UserName", GetType(String))
            dt.Columns.Add("Education", GetType(String))
            dt.Rows.Add(1, "Suresh Dasari", "B.Tech")
            dt.Rows.Add(2, "Rohini Dasari", "Msc")
            dt.Rows.Add(3, "Madhav Sai", "MS")
            dt.Rows.Add(4, "Praveen", "B.Tech")
            dt.Rows.Add(6, "Sateesh", "MD")
            dt.Rows.Add(7, "Mahesh Dasari", "B.Tech")
            dt.Rows.Add(8, "Mahendra", "CA")
            gvUserInfo.DataSource = dt
        End If
    End Sub
End Class

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...

Thank U Suresh

Anonymous said...

Please contact me @8446012354. I have business proposal.

priyanka said...

Thanx Sir.. I can Beleive Yor Code Blindly.. it Aways Solves My Problems...

Unknown said...

but i dont have footer row

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.