简体   繁体   中英

Find gridview from parent ascx control using client side code

I have a user control call parent.ascx and i load inside a child.ascx. In the child control i have a gridview and i want to access it using javascript from parent ascx control. I am using the following code but it doesnt found it. Any help?.

      var grid = document.getElementById("<%= child_grdrisk.ClientID %>");

   alert(grid.rows.length);

You can get the nr of rows like this:

var rowsCount = <%=child_grdrisk.Rows.Count %>;

or you could store the nr of rows in a hidden field and get the nr of rows from it:

hiddenField1.Value = child_grdrisk.Rows.Count.ToString();

var rowsCount = document.getElementById('<%= hiddenField1.ClientID %>');

or you can use jQuery:

var rowsCount = $("#<%= grdrisk.ClientID %> tr").length;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM