Click here to Skip to main content
12,953,065 members (59,221 online)
Rate this:
Please Sign up or sign in to vote.
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"
 <asp:datagrid style="Z-INDEX: 0" id="dgDetails" Runat="server" Width="75%" ShowFooter="True" AllowSorting="True" AutoGenerateColumns="False" OnSortCommand="dgDetails_SortCommand">

Jquery code:
$(document).ready(function () {
       var height = $('#dgDetails').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
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.
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?
Rate this: bad
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.
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,920

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2017
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