Datagrid Width At Runtime

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
 
I

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.
 
I

Iain

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top