Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按客户端屏幕大小调整网格大小_C#_Asp.net_Datagrid_Client_Screen - Fatal编程技术网

C# 按客户端屏幕大小调整网格大小

C# 按客户端屏幕大小调整网格大小,c#,asp.net,datagrid,client,screen,C#,Asp.net,Datagrid,Client,Screen,我想通过客户端屏幕大小设置datagrid在页面加载时的大小。有没有办法在页面加载或服务器端的其他页面事件中获得此大小 我使用了Request.Browser.ScreenPixelsWidth和Request.Browser.screenpixelshight,但这些尺寸不是真的。这些大小始终为640*480。您可以使用Javascript获取视口的宽度和高度。然后通过隐藏的表单输入或ajax将值传回 var width = $(window).width(); var height = $(

我想通过客户端屏幕大小设置datagrid在页面加载时的大小。有没有办法在页面加载或服务器端的其他页面事件中获得此大小


我使用了
Request.Browser.ScreenPixelsWidth
Request.Browser.screenpixelshight
,但这些尺寸不是真的。这些大小始终为640*480。

您可以使用Javascript获取视口的宽度和高度。然后通过隐藏的表单输入或ajax将值传回

var width = $(window).width();
var height = $(window).height();
首先,添加这些隐藏的表单输入以存储宽度和高度,直到回发

<asp:HiddenField ID="width" runat="server" />
<asp:HiddenField ID="height" runat="server" />

我希望它可以帮助您……

请求.浏览器.屏幕像素宽度
请求.浏览器.屏幕像素高度
无法在服务器端提供客户端屏幕分辨率

最好的方法是使用javascript-

<%if (!this.IsPostBack)
{%>
<script language="javascript" type="text/javascript">
var rowURL = window.location.href;
var screenWidth = window.screen.availWidth;
if (rowURL.indexOf("screen_width") == -1)
window.location.href = window.location.href + "?screen_width=" + screenWidth;
</script>
<%}%>

var rowURL=window.location.href;
var screenWidth=window.screen.availWidth;
if(rowURL.indexOf(“屏幕宽度”)=-1)
window.location.href=window.location.href+“?screen_width=“+screenWidth;
在页面的“body”标记中使用此脚本。 它只是将'screen_width'参数附加到查询字符串并刷新页面。
通过这种方式,您可以从查询字符串中获取服务器端的“屏幕宽度”值。

是否可以使用百分比大小?请尝试将“宽度-高度”设置为“百分比”,然后查看在调整浏览器窗口的大小时它是否会调整大小。@mortb:这是不可能的;我需要在页面的某个事件中使用这些大小,但您的解决方案不适合我。您需要在客户端或服务器端事件中调整大小吗?我需要在服务器端调整大小。如果需要,您可以访问服务器端的隐藏字段值。我需要在页面加载中使用这些值,但您的解决方案会在加载后获得值。
var TheBrowserWidth = width.Value;
var TheBrowserHeight = height.Value;
<%if (!this.IsPostBack)
{%>
<script language="javascript" type="text/javascript">
var rowURL = window.location.href;
var screenWidth = window.screen.availWidth;
if (rowURL.indexOf("screen_width") == -1)
window.location.href = window.location.href + "?screen_width=" + screenWidth;
</script>
<%}%>