Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript VB.NET
function GridVal() 
{
    var app_id = document.getElementById ('ctl00_contentMain_ddl_Approach').value;
                 if (app_id =="1008") 
                 {      
                   var cellInstr;
                   var cellInstr1;
                   var grid = document.getElementById("<%= QueGrid.ClientID %>");
                   var txt1 = document.getElementById("txt_QuestionAssessmentInstruction");  
                     for (i=1; i<=grid.rows.length; i++)
                        { 
                          alert("for");   
                          alert(i);                     
                          cellInstr = grid.rows[i].cells[4];                                 
                          alert(cellInstr);                              
                          var CInstruc = cellInstr.childNodes[0].value;
                              alert(CInstruc); 
                         if(CInstruc=="")
                         {
                           alert("if");   
                           alert("The field Question Instruction cannot be Empty");
                           cellInstr.childNodes[0].focus();
                           return false;
                         }
                       }
                 }
                 else
                 {
                   var cellInstr;                
                   var grid = document.getElementById("<%= BUGrid.ClientID %>");
                   var txt1 = document.getElementById("txtControlTI");       
                     for (i=0; i<grid.rows.length;>
                        {                              
                          cellInstr = grid.rows[i].cells[6];
                          alert(cellInstr);                             
                          var CInstruc = cellInstr.childNodes[0].value;                       
                             alert(CInstruc);
                         if(CInstruc=="")
                         {
                            alert("The field Control Instruction cannot be Empty");
                            cellInstr.childNodes[0].focus();
                            return false;
                         }                        
                       }
                      }
}
In my above code i have used QueGrid as datagrid i want to give alert msg for number of rows in datagrid how can i get number of rows for the grid
Posted 27-Jun-13 22:25pm
Edited 27-Jun-13 22:34pm
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Refer - ASP.NET GridView row count using Javascript[^].
var rowscount = document.getElementByID('<%=Gridview1.ClientID%>').rows.length;
 
alert(rowscount);
Comments
Member 9410081 at 28-Jun-13 5:12am
   
i tried the other one stilll its not working
Tadit Dash at 28-Jun-13 5:46am
   
Then put a debugger and see what is the problem. You can put that by adding the code debugger; inside javaScript code.
 
And yes, please see the Console Window of FireBug in FireFox, if there are any issues reported.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

var grid = document.getElementById("<%=QueGrid.ClientID %>");
var rowCount = grid.getElementsByTagName('TR').length -1;
  Permalink  
Comments
Member 9410081 at 28-Jun-13 4:59am
   
i used the above code but it is giving following error.
 
Message: 'null' is null or not an object
Line: 160
Char: 1
Code: 0
Mahesh Bailwal at 28-Jun-13 5:49am
   
Where are you using this script in Head section or in Body section of .aspx page
Mahesh Bailwal at 28-Jun-13 6:05am
   
It seems like you trying to get row count before grid is fully loaded. Please add this script just before end of body tag in .aspx page.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try this ....Smile | :)
 
DataTable dt = //configure datasource here 
GridView1.DataSource = dt;
GridView1.DataBind();
 
you can take a hiddenfield html control in your page and can assign its value when you bind your grid as
 
HiddenField1.value = GridView1.Rows.Count.ToString(); // HiddenField1 is your hiddent type with server tag

 

In your javascript you can get its value as
 
var count = document.getElementById('HiddenField1');
 
alert(count.value)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 28 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100