<asp:GridView ID="GVItemList" runat="server" AutoGenerateColumns="False" EnableTheming="True" GridLines="None">
    <Columns>
       <asp:TemplateField>
         <ItemTemplate>
           <table border="0" cellpadding="0" cellspacing="0" style="width:700px">
               <tr>
                  <td><span style="color:#003399; font-size:3"><iframe src="http://192.168.1.6:81/html/PM/<%# Eval("roomid")%>.htm" width="700px" frameborder="0" id="frmsrc" marginheight="0"></iframe></span></td>
                </tr>
            </table>
          </ItemTemplate>
        <ItemStyle CssClass="ContextMenuColumn" />
        </asp:TemplateField>
    </Columns>
</asp:GridView>如上我在GridView中使用模板列中的iframe 连接不同htm页面(没有跨域),但高度不能动态改变,每个htm页面的高度不同的,我用过类似
parent.document.all("框架ID名").style.height=document.body.scrollHeight; 
很多javascript 都不管用。 请各位高手帮帮忙,如何让高度自适。

解决方案 »

  1.   

    http://community.csdn.net/Expert/topic/5734/5734046.xml?temp=.9440271
      

  2.   

    document.body.scrollHeight是当前窗口的文档高度:
    parent.document.all("框架ID名").style.height=document.body.scrollHeight; 
    =>>
    document.all("框架ID名").height=document.all("框架ID名").contentWindow.document.body.scrollHeight;
      

  3.   

    另外<iframe还得加个name:
    name="frmsrc"
      

  4.   

    这个我也碰见过....当时解决方法就是让这个iframe高度很大 这样就行了= =
      

  5.   

    回wangkun9999(蜘蛛+Lucene.net构建搜索引擎) 
    <script type="text/javascript">
            function auto()
            {
                document.all("frmsrc").height=document.all("frmsrc").contentWindow.document.body.scrollHeight;
            }
    </script>
    <body onload="auto()"> 
    我这样用的,iframe也加 name="frmsrc" 高度还是固定的。。
      

  6.   

    iframe高度很大。。就很难看了 我不是用一个iframe啊,有多少数据有多少个iframe
      

  7.   

    不用iframe用啥呢。。别的页面内容直接在本页显示
      

  8.   

    写一段js啊!!
    function iframeAutoFit()
    {
        try
        {
            var iframes = document.getElementsByTagName("IFRAME");
            for(var i=0; i<iframes.length; i++) //author:meizz
            {
                if (iframes[i] && !window.opera)
                {
                    iframes[i].style.display="block"
                    if (iframes[i].contentDocument && iframes[i].contentDocument.body.offsetHeight)//如果用户的浏览器是NetScape
                    {
                        iframes[i].height = iframes[i].contentDocument.body.offsetHeight; 
                    }
                    else if (iframes[i].Document && iframes[i].Document.body.scrollHeight) //如果用户的浏览器是IE
                    {
                        iframes[i].height = iframes[i].Document.body.scrollHeight;
                    }
                }
            }
        }
        catch (ex){}
    }if(window.attachEvent)
    {
        window.attachEvent("onload",  iframeAutoFit);
         //window.attachEvent("onresize",  iframeAutoFit);
    }
    else if(window.addEventListener)
    {
        window.addEventListener('load',  iframeAutoFit,  false);
        //window.addEventListener('resize',  iframeAutoFit,  false);
    }
      

  9.   

    回michael555cdj()  你的方法我试了。 不行,高度不变。 
    我的iframe 的id 也是变量 id="<%# Eval("roomid")%>"
      

  10.   

    我的iframe 的id 也是变量 id="<%# Eval("roomid")%>"晕...........太有难度了  关注学习
      

  11.   

    <iframe onload="this.style.hight=this.document.body.clientHeight; this.style.width=this.document.body.clientWidth;">
      

  12.   

    <td><span style="color:#003399; font-size:3"><iframe src="http://192.168.1.6:81/html/PM/<%# Eval("roomid")%>.htm" width="700px" frameborder="0" id="frmsrc<%# Eval("roomid")%>" marginheight="0"></iframe></span></td>在<%# Eval("roomid")%>.htm里面写window.onload = function()
    {
     var roomid = window.location.href
     roomid = roomid.substr(roomid.lastIndex("/"))
     roomid = roomid.substr(0,roomid.indexOf(".")
     parent.document.getElementById("frmsrc" + roomid).style.height=document.body.scrollHeight;
     
    }
      

  13.   

    好的写法
    <td><span style="color:#003399; font-size:3"><iframe src="http://192.168.1.6:81/html/PM/<%# Eval("roomid")%>.htm" width="700px" frameborder="0" id="frmsrc<%# Eval("roomid")%>" marginheight="0"></iframe></span></td>在<%# Eval("roomid")%>.htm里面写window.onload = function()
    {
     var roomid = window.location.href
     roomid = roomid.substr(roomid.lastIndex("/"))
     roomid = roomid.substr(0,roomid.indexOf(".")
     alert(roomid) //看是否是正确的id
    var eleHeight
    if(document.documentElement)
    eleHeight = document.documentElement.scrollHeight
    else
    eleHeight = document.body.scrollHeight parent.document.getElementById("frmsrc" + roomid).style.height=eleHeight + "px";
     
    }
      

  14.   

    修改一下<script>
    window.onload = function()
    {
     var roomid = window.location.href
     roomid = roomid.substr(roomid.lastIndexOf("/")+1)
     roomid = roomid.substr(0,roomid.indexOf("."))
     var eleHeight
    if(document.documentElement)
    eleHeight = document.documentElement.scrollHeight
    else
    eleHeight = document.body.scrollHeight parent.document.getElementById("frmsrc" + roomid).style.height=eleHeight + "px";
     
    }</script>
      

  15.   

    <iframe src="http://192.168.1.6/html/AM/<%# Eval("roomid")%>.htm" width="700px" frameborder="0" marginheight="0" onload="javascript:{dyniframesize(<%# Eval("roomid")%>);}" id="<%# Eval("roomid")%>" scrolling="no"></iframe>
    <script type="text/javascript">
    function dyniframesize(id)
        {
            AutoIframe(id);
        }
        function AutoIframe(id)
        {
            if(document.readyState!='complete')
            {
                setTimeout( function(){AutoIframe(id);},25 );
                return;
            }
            else
            {
                var ifobj=document.getElementById(id);            ifobj.height= ifobj.contentWindow.document.body.scrollHeight;
            }
        }
    </script>