GridView.Columns.Insert Problems

Discussion in 'ASP .Net Web Controls' started by Harry Keck, Feb 9, 2007.

  1. Harry Keck

    Harry Keck Guest

    I have a GridView that I dynamically add columns to in code. The way that my
    code is written, everything works properly if I use GridView.Columns.Add to
    simply add the columns to the end of the collection. However, if I use
    GridView.Columns.Insert to inject the columns in the middle of the existing
    columns, I see lots of exceptions when I page the GridView, because certain
    controls contained within the grid are mysteriously absent? Can anyone
    explain what the difference is between Add and Insert that would cause
    problems?
     
    Harry Keck, Feb 9, 2007
    #1
    1. Advertising

  2. Harry Keck

    Harry Keck Guest

    I think I can see what is happening, but I still do not know why. My
    GridView has a number of TemplateFields declared directly in the aspx. I
    then use GridView.Columns.Insert to add a couple of BoundFields to the grid.
    Any subsequent time that I bind data to the GridView after calling Insert,
    all of the TemplateFields are empty. If I change my code to use Collumns.Add
    in place of Collumns.Insert, the Template Fields do not empty. What is going
    on?

    "Harry Keck" wrote:

    > I have a GridView that I dynamically add columns to in code. The way that my
    > code is written, everything works properly if I use GridView.Columns.Add to
    > simply add the columns to the end of the collection. However, if I use
    > GridView.Columns.Insert to inject the columns in the middle of the existing
    > columns, I see lots of exceptions when I page the GridView, because certain
    > controls contained within the grid are mysteriously absent? Can anyone
    > explain what the difference is between Add and Insert that would cause
    > problems?
     
    Harry Keck, Feb 9, 2007
    #2
    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. helpful sql
    Replies:
    0
    Views:
    818
    helpful sql
    May 19, 2005
  2. loga123
    Replies:
    0
    Views:
    1,917
    loga123
    May 23, 2006
  3. Jacksm
    Replies:
    2
    Views:
    855
    Paul Chalekian
    Nov 21, 2006
  4. =?Utf-8?B?SGFycnkgS2Vjaw==?=

    GridView.Columns.Insert Problems

    =?Utf-8?B?SGFycnkgS2Vjaw==?=, Feb 9, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    677
    =?Utf-8?B?SGFycnkgS2Vjaw==?=
    Feb 9, 2007
  5. Vinki

    template columns and bound columns in gridview

    Vinki, Apr 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    871
    Vinki
    Apr 25, 2007
Loading...

Share This Page