Click here to Skip to main content
15,885,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends,
I have div inside which there is grid.

I want to do following:
1. get the height of the grid after it is rendered.
2. set the heiht of the div based on the height of the grid.

.ASPX code:
<div style="WIDTH: 948px; HEIGHT: 450px; OVERFLOW: auto" id="divDetails" align="center"
							 runat="server">
 <asp:datagrid style="Z-INDEX: 0" id="dgDetails" Runat="server" Width="75%" ShowFooter="True" AllowSorting="True" AutoGenerateColumns="False" OnSortCommand="dgDetails_SortCommand">
.
.
.		
</asp:datagrid> 						
</div>


Jquery code:
$(document).ready(function () {
       var height = $('#dgDetails').height();
       alert(height);
       });


I always get he null value in alert.
May i know where I'm going wrong??

Thanks in advance
Posted

Yes,it will give only null values because on page load client script execute first then gridview will load.Call this script after loading gridview.You can put this script at the end of the page.If its not worked then call this script after grid view bind by creating one javascript function from page behind.
 
Share this answer
 
Comments
dhage.prashant01 21-Feb-13 5:13am    
Even pasting the code at the end of page
the value is still null
Should i try the code in render event of the page?
Please correct the selector,You are selecting wrong Selector Id its $('#divDetails').height()not $('#dgDetails').height();
I tried it works.
 
Share this answer
 
Comments
dhage.prashant01 22-Feb-13 4:30am    
I want to set divDetails height based on height of dgDetails
So below code is perfect
var height = $('#dgDetails').height();

height will be then assigned to the div

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