Gridview Column Width

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yin99

    #1

    Gridview Column Width

    I have a Gridview binding to a DataTable source. I'd like to set the
    column with of the second column. I cannot do this apparently because
    when AutoGenerateCol umns=true, they do not appear in the columns
    collection.

    I modified the RowCreated even to gridview, and I can change
    properties on the cells, but not width. (setting tooltip, background
    color, etc, all work but changing width has no effect). Here's
    sample code I am using:

    //Inside RowCreated Gridview Even
    if (e.Row.RowType == DataControlRowT ype.DataRow)
    {
    foreach (TableCell tCell in e.Row.Cells)
    {
    tCell.ControlSt yle.Width = 600; //no effect
    tCell.Width = 600; //no effect
    }
    }

    So the main question is, "Any way possible to change Gridview Column
    Width with a DataTable source and AutoGenerateCol umns=true?" Please
    Help, I am at a loss here and been working on this for days....

    -Yin

    PS
    little more background- I have a dynamic DataTable (could be 1 to
    over 3000 columns), so I must have AutoGenerateCol umns=true (I can't
    set it to false, and create a boundfield for an unknown dynamic sized
    table).
  • Liz

    #2
    Re: Gridview Column Width


    << little more background- I have a dynamic DataTable (could be 1 to
    over 3000 columns), so I must have AutoGenerateCol umns=true (I can't
    set it to false, and create a boundfield for an unknown dynamic sized
    table) >>

    you're kidding, right? up to 3000 columns? .... this is software ... to be
    used by humans ... not alchemy

    leaving that aside (which you should not) it doesn't seem advisable to alter
    column width every time a row is created; have you considered all the work
    for the processor you're creating here .... I hate to ask how many rows
    there may be in the control ...


    "Yin99" <ws@ziowave.com wrote in message
    news:7c399386-bd6d-4563-87db-f1d09241031f@b4 0g2000prf.googl egroups.com...
    >I have a Gridview binding to a DataTable source. I'd like to set the
    column with of the second column. I cannot do this apparently because
    when AutoGenerateCol umns=true, they do not appear in the columns
    collection.
    >
    I modified the RowCreated even to gridview, and I can change
    properties on the cells, but not width. (setting tooltip, background
    color, etc, all work but changing width has no effect). Here's
    sample code I am using:
    >
    //Inside RowCreated Gridview Even
    if (e.Row.RowType == DataControlRowT ype.DataRow)
    {
    foreach (TableCell tCell in e.Row.Cells)
    {
    tCell.ControlSt yle.Width = 600; //no effect
    tCell.Width = 600; //no effect
    }
    }
    >
    So the main question is, "Any way possible to change Gridview Column
    Width with a DataTable source and AutoGenerateCol umns=true?" Please
    Help, I am at a loss here and been working on this for days....
    >
    -Yin
    >
    PS
    little more background- I have a dynamic DataTable (could be 1 to
    over 3000 columns), so I must have AutoGenerateCol umns=true (I can't
    set it to false, and create a boundfield for an unknown dynamic sized
    table).

    Comment

    • Yin99

      #3
      Re: Gridview Column Width

      On Dec 10, 11:10 am, "Liz" <l...@tiredofsp am.comwrote:
      << little more background- I have a dynamic DataTable (could be 1 to
      over 3000 columns), so I must have AutoGenerateCol umns=true (I can't
      set it to false, and create a boundfield for an unknown dynamic sized
      table) >>
      >
      you're kidding, right? up to 3000 columns? .... this is software ... to be
      used by humans ... not alchemy
      >
      leaving that aside (which you should not) it doesn't seem advisable to alter
      column width every time a row is created; have you considered all the work
      for the processor you're creating here .... I hate to ask how many rows
      there may be in the control ...
      >
      "Yin99" <w...@ziowave.c omwrote in message
      >
      news:7c399386-bd6d-4563-87db-f1d09241031f@b4 0g2000prf.googl egroups.com...
      >
      >
      >
      I have a Gridview binding to a DataTable source. I'd like to set the
      column with of the second column. I cannot do this apparently because
      when AutoGenerateCol umns=true, they do not appear in the columns
      collection.
      >
      I modified the RowCreated even to gridview, and I can change
      properties on the cells, but not width. (setting tooltip, background
      color, etc, all work but changing width has no effect). Here's
      sample code I am using:
      >
      //Inside RowCreated Gridview Even
      if (e.Row.RowType == DataControlRowT ype.DataRow)
      {
      foreach (TableCell tCell in e.Row.Cells)
      {
      tCell.ControlSt yle.Width = 600; //no effect
      tCell.Width = 600; //no effect
      }
      }
      >
      So the main question is, "Any way possible to change Gridview Column
      Width with a DataTable source and AutoGenerateCol umns=true?" Please
      Help, I am at a loss here and been working on this for days....
      >
      -Yin
      >
      PS
      little more background- I have a dynamic DataTable (could be 1 to
      over 3000 columns), so I must have AutoGenerateCol umns=true (I can't
      set it to false, and create a boundfield for an unknown dynamic sized
      table).- Hide quoted text -
      >
      - Show quoted text -
      nope, it's a timespread and not really processor intensive. but still
      the question remains, why in the world
      can I not change a column width to a DataTable source with
      AutoGenerateCol umns=true?
      Woudln't this be something a lot of people would want to do?

      I can't imagine the only answer is to turn AutoGenerateCol umns=false,
      and add a bound field, map this
      to the datatable, etc. Please, anyone out there know the answer?
      Thanks!

      Comment

      • Yin99

        #4
        Re: Gridview Column Width

        i was able to make a workaround by adding a bunch of spaces to the
        header row column but
        still unable to get the .Width property to explicitly change the
        column width on header row or
        datarows.

        here's sample code:

        if (e.Row.RowType == DataControlRowT ype.Header)
        {
        if (e.Row.Cells[1].Text == "Column Header Text")
        {
        e.Row.Cells[1].Wrap = false;
        e.Row.Cells[1].Width = Unit.Percentage (1000);
        e.Row.Cells[1].Text = "Column Header Text " +
        "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
        "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
        "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
        "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
        "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
        "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
        "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
        "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp";
        }

        Comment

        • Liz

          #5
          Re: Gridview Column Width


          "Yin99" <ws@ziowave.com wrote in message
          news:564c73f3-d7cf-49e6-8586-b85d4ee00f55@d2 7g2000prf.googl egroups.com...
          >i was able to make a workaround by adding a bunch of spaces to the
          header row column but
          still unable to get the .Width property to explicitly change the
          column width on header row or
          datarows.

          well ... I fooled around with this and I can get .Width property to
          "influence" the width of the cell; if I set it to 5, it'll make it as small
          as possible, and if I set it to 2000, it'll make it as wide as possible ...
          but it will not just use the metric supplied absolutely

          but here's the thing: if you look at the HTML source you should see:

          <td style="width:20 00px;">

          if you set your Width to 2000, for example; so the code does what you ask
          it to but the browser (IE6 in this case) just renders it as it "wants to"
          .....


          here's sample code:
          >
          if (e.Row.RowType == DataControlRowT ype.Header)
          {
          if (e.Row.Cells[1].Text == "Column Header Text")
          {
          e.Row.Cells[1].Wrap = false;
          e.Row.Cells[1].Width = Unit.Percentage (1000);
          e.Row.Cells[1].Text = "Column Header Text " +
          "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
          "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
          "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
          "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
          "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
          "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
          "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp" +
          "&nbsp&nbsp&nbs p&nbsp&nbsp&nbs p&nbsp&nbsp";
          }


          Comment

          Working...