Datagrid Width At Runtime

Discussion in 'ASP .Net' started by Iain, Jan 6, 2010.

  1. Iain

    Iain Guest

    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
     
    Iain, Jan 6, 2010
    #1
    1. Advertising

  2. Iain

    Abdul Sami Guest

    Try .Value.ToString()

    --
    Abdul Sami


    "Iain" wrote:

    > 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
    > .
    >
     
    Abdul Sami, Jan 6, 2010
    #2
    1. Advertising

  3. Iain

    Iain Guest

    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.
     
    Iain, Jan 6, 2010
    #3
  4. Iain

    Iain Guest

    On 6 Jan, 13:06, "Mark Rae [MVP]" <> wrote:
    > "Iain" <> wrote in message
    >
    > news:...
    >
    > > Mark. I will certainly look at the GridView control and see if I can
    > > get any better results there.

    >
    > 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...
    >
    > --
    > Mark Rae
    > ASP.NET MVPhttp://www.markrae.net


    Sorry Mark

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

    Thanks
     
    Iain, Jan 6, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AndrewF
    Replies:
    1
    Views:
    822
    Bruce Barker
    Oct 10, 2005
  2. Xu
    Replies:
    11
    Views:
    8,627
    Andrew Thompson
    Jul 16, 2005
  3. Sean Jorden
    Replies:
    1
    Views:
    616
    laurie
    Aug 19, 2003
  4. kris
    Replies:
    11
    Views:
    894
  5. Paul Furman

    min-width max-width again

    Paul Furman, Feb 9, 2004, in forum: HTML
    Replies:
    10
    Views:
    720
    Beauregard T. Shagnasty
    Feb 9, 2004
Loading...

Share This Page