首先你已經把你的GridView
放入某個div。將屬性高度設置爲100% !importantant
。關於JS函數動態編輯div高度,請嘗試遵循此示例爲我工作。
編輯的.css
<style>
/*Set height 100% !important*/
.grid_style {
height: 100% !important;
width: 100% !important;
}
編輯的.aspx
<div class="grid_conteiner" id="grid_conteiner" style="height: 500px;">
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" GridLines="None" CssClass="grid_style">
</telerik:RadGrid>
編輯JS headerHeight值您需要更改並設置標題的高度,同樣可以使用footerHeight。
<script type="text/javascript">
function getWindowHeight() {
var functionReturn = 0;
if ((document.documentElement) && (document.documentElement.clientHeight))
functionReturn = document.documentElement.clientHeight;
else if ((document.body) && (document.body.clientHeight))
functionReturn = document.body.clientHeight;
else if ((document.body) && (document.body.offsetHeight))
functionReturn = document.body.offsetHeight;
else if (window.innerHeight)
functionReturn = window.innerHeight - 18;
functionReturn = parseInt(functionReturn);
if ((isNaN(functionReturn) === true) || (functionReturn < 0))
functionReturn = 0;
return functionReturn;
};
window.onresize = function(event) {
var gridC = document.getElementById("grid_conteiner");
if (gridC != null) {
//Here set in px height of header
var headerHeight = 120;
//Here set in px height of your fooer
var footerHeight = 80;
//Here is getting window height
var winHeight = getWindowHeight();
//Here is set dynamically height to conteiner
document.getElementById('grid_conteiner')
.setAttribute("style", "height:" + (winHeight - headerHeight - footerHeight) + "px");
}
};
</script>
謝謝你很多@mww :) – swifty