6 Answers, 1 is accepted
0
Hi Andy,
When you set the width to 100%, the grid is resized to fill its parent container.
So in server-side you do not know what will be the actual width of the grid. For example if you have only one grid in the page when you resize the browser window the grid width will be changed.
You can get the width client-side. Like in the example bellow:
Kind regards,
Vasil
the Telerik team
When you set the width to 100%, the grid is resized to fill its parent container.
So in server-side you do not know what will be the actual width of the grid. For example if you have only one grid in the page when you resize the browser window the grid width will be changed.
You can get the width client-side. Like in the example bellow:
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
language
=
"javascript"
>
function clientClick() {
var width = $get("<%=RadGrid1.ClientID%>").clientWidth;
alert(width);
}
</
script
>
</
telerik:RadCodeBlock
>
<
div
>
<
input
id
=
"btnClient"
type
=
"button"
value
=
"Check the width"
onclick
=
"clientClick();"
/>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
>
........
</
telerik:RadGrid
>
Kind regards,
Vasil
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0

Andy
Top achievements
Rank 1
answered on 25 Feb 2011, 11:08 PM
Very useful answer
Thanks Vasil!
ANdy.
Thanks Vasil!
ANdy.
0

Andy
Top achievements
Rank 1
answered on 01 Mar 2011, 06:32 PM
Hi Vasil,
I would like to know the RadGrid width on the page load.
So I use
It's good on IE6.
But I can't get the width on IE8.
Thanks,
Andy.
I would like to know the RadGrid width on the page load.
So I use
window.onload =
function
() {
var
width = $get(
"<%=myGrid.ClientID%>"
).clientWidth;
var
mydiv = document.getElementById(
"mydiv"
);
alert(width);
mydiv.style.marginLeft = Math.abs((980 - width) / 2);
alert(
"Result = "
+ Math.abs((980 - width) / 2));
}
It's good on IE6.
But I can't get the width on IE8.
Thanks,
Andy.
0
Hi Andy,
I get a similar result here except that it works on IE8, but not work on IE7 (it alert 0 width).
Using offsetWidth property instead of clientWidth will fix this problem.
Best wishes,
Vasil
the Telerik team
I get a similar result here except that it works on IE8, but not work on IE7 (it alert 0 width).
Using offsetWidth property instead of clientWidth will fix this problem.
Best wishes,
Vasil
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0

Hung Ha
Top achievements
Rank 1
answered on 02 Mar 2011, 04:40 PM
Hi Vasil,
Like a charm, you solve the problem.
However, it just works in IE, not in Chrome, or Firefox
Thanks.
Like a charm, you solve the problem.
However, it just works in IE, not in Chrome, or Firefox
Thanks.
0
Hi,
Using offsetWidth should work on all browsers. If you use it inside another function, please check that all other properties that you are using are also avaiable in Firefox.
Kind regards,
Vasil
the Telerik team
Using offsetWidth should work on all browsers. If you use it inside another function, please check that all other properties that you are using are also avaiable in Firefox.
Kind regards,
Vasil
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!