Datagrid Width At Runtime

  • Thread starter Thread starter Iain
  • Start date Start date
I

Iain

Hi all

I have a datagrid in a web form and I want to be able to determine the
width of the datagrid at runtime.

I have tried both of the following

// Get the width using the datagrid width attribute.
double datagridWidth = 0;
datagridWidth = dgProjects.Width.Value;

and

// Add the widths of all columns
double dgWidth = 0;

for (int i = 0; i <= dgProjects.Columns.Count - 1; i++)
{
dgWidth = dgWidth + dgProjects.Columns
.ItemStyle.Width.Value;
}


Neither of these returns the width. All values are 0.0.

Is there any kind soul out there who knows how to do this.

Many thanks in advance for any assistance offered

Iain
 
Thanks Abdul, but that just converts a zero value to a string.

Mark. I will certainly look at the GridView control and see if I can
get any better results there.

Watch this space.

Thanks guys.
 
The GridView won't give you any better results than the DataGrid in this
particular case because, as mentioned, you almost certainly won't be able to
do this server-side so, at that level, it won't matter one iota which
webcontrol you use...

My suggestion to upgrade the DataGrid to the GridView was simply to
encourage you to move away from obsolete technology...

Sorry Mark

I should have made my response clearer. That was my intention. To move
to newer technology.

Thanks
 
Back
Top