如何使用jquery获取网格的动态高度 [英] how to get dynamic height of grid using jquery

查看:82
本文介绍了如何使用jquery获取网格的动态高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我有div里面有网格。



我想做以下事项:

1.渲染后得到网格的高度。

2.根据网格的高度设置div的高度。



.ASPX代码:

< div style =WIDTH:948px; HEIGHT:450px ; OVERFLOW:autoid =divDetailsalign =center
runat =server>
< asp:datagrid style =Z-INDEX:0id =dgDetailsRunat =serverWidth =75%ShowFooter =TrueAllowSorting =TrueAutoGenerateColumns =FalseOnSortCommand = dgDetails_SortCommand >



< / asp:datagrid>
< / div>





Jquery代码:

 $(document).ready(function(){
var height = $(''#dgDetails'')。height();
alert(身高);
});





我总是在警报中获得空值。

我可以知道我在哪里'出错了?



提前谢谢

解决方案

(文件).ready(function( ){
var height =


(''#dgDetails'')。height();
alert(height);
});





我总是在警报中获得空值。

我可以知道我在哪里'出错了?



提前谢谢


是的,它只会给出空值,因为在页面加载客户端脚本首先执行,然后gridview将加载。加载gridview后调用此脚本。您可以将此脚本放在页面的末尾。如果它不起作用,则在网格视图绑定后通过从页面后面创建一个javascript函数来调用此脚本。

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

解决方案

(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


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.


这篇关于如何使用jquery获取网格的动态高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆