Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir,
I want to check No.of Rows in Grid View from Client Side. Like Text Box. Ex.
C#
<script language="javascript" type="text/javascript">
function IsValid()
{
 var fname=document.getElementById("<%=txtFName.ClientID%>").value;
 if(fname=="")
 {
   alert("Please Enter Name");
   document.getElementById("<%=txtFName.ClientID%>").focus();
   return false;
 }
}
</script>
Posted
Comments
Peter Leow 20-Feb-15 9:10am    
Your question title and your example did not tally...

Hi,

On the client side, a grid view is an html table.

In JavaScript, to get the number of rows on an html table, you would check the length of the tables row collection.

Access your GridView using its ClientID property, and you have a reference to your html table.

Something like this should work:
JavaScript
var gridViewRowCount=document.getElementByID('<%=gv.ClientID%>').rows.length;


... Hope it helps.
 
Share this answer
 
Comments
Kuthuparakkal 21-Feb-15 15:53pm    
+5
 
Share this answer
 
v2
You need to create object of your link first and then add attributes to it. check below code -

C#
foreach (GridViewRow row in gv1.Rows)
 {
    //Creates object of button inside your gridView Row
    Button btnRowCommand = (Button)row.FindControl("YourButtonName");
    //Adds Attribute to buttonng="sql">button - in this case adds onclick attribute
    //which will fire the
    //gv1RowCommand(ID); javascript function
    btnRowCommand.Attributes.Add("onclick", "gv1RowCommand('"+ ID +"');");
 }

function gv1RowCommand(ID) {
alert('Row command test');
}
 
Share this answer
 
v2

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