Rauf
Rauf

Reputation: 12842

GridView JavaScript

How to check whether an ASP.NET GridView has atleast one row, using JavaScript?

Upvotes: 0

Views: 1060

Answers (3)

jebberwocky
jebberwocky

Reputation: 1089

just wondering why count the Dom element

var _count = '<%=GridView1.Rows.Count %>';
var rowcount = (_count)?_count:0;

Upvotes: 2

kbvishnu
kbvishnu

Reputation: 15630

using Jquery find the ID of your gridview

 var rowCount = $('#<%=gridview.ClientID%> tr').length;

rowCount will get the value of the total rows.If it is 1 then it contains only only headers.

Upvotes: 1

Fraz Sundal
Fraz Sundal

Reputation: 10448

GridView is rendered as an Html table so you just access it in javascript like

var grid = document.getElementById('<%=GridViewId.ClientID %>');
var totalrowcount = grid.rows.length;

Upvotes: 1

Related Questions