Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET jQuery
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 20-Feb-13 19:30pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please correct the selector,You are selecting wrong Selector Id its $('#divDetails').height()not $('#dgDetails').height();
I tried it works.
  Permalink  
Comments
dhage.prashant01 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
dhage.prashant01 at 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?

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

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 OriginalGriff 394
2 thatraja 370
3 Sergey Alexandrovich Kryukov 329
4 CPallini 179
0 OriginalGriff 697
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 495
3 thatraja 370
4 Sergey Alexandrovich Kryukov 344


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 21 Feb 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