datagrid column exists

Discussion in 'ASP .Net' started by gane, Jun 5, 2006.

  1. gane

    gane Guest

    Hi,

    I am creating datagrid bound column dynamically and need to check if a
    datagrid column already exists?Is there a way to check this?

    thanks
    gane
     
    gane, Jun 5, 2006
    #1
    1. Advertising

  2. Is datagrid's Columns collection good for you? Note, that autogenerated
    columns don't get there.

    Eliyahu

    "gane" <> wrote in message
    news:...
    > Hi,
    >
    > I am creating datagrid bound column dynamically and need to check if a
    > datagrid column already exists?Is there a way to check this?
    >
    > thanks
    > gane
    >
     
    Eliyahu Goldin, Jun 6, 2006
    #2
    1. Advertising

  3. gane

    gane Guest

    Hi,

    Can you show me with a sample code?
    I have something like this, i need to check if the column exists before i
    add to the grid. how can i do with the collections.
    foreach(DataColumn c in dsinfo.Tables[0].Columns)

    {

    dgresults.Columns.Add(CreateBoundColumn(c));

    }

    Thanks

    "Eliyahu Goldin" <> wrote in message
    news:...
    > Is datagrid's Columns collection good for you? Note, that autogenerated
    > columns don't get there.
    >
    > Eliyahu
    >
    > "gane" <> wrote in message
    > news:...
    >> Hi,
    >>
    >> I am creating datagrid bound column dynamically and need to check if a
    >> datagrid column already exists?Is there a way to check this?
    >>
    >> thanks
    >> gane
    >>

    >
    >
     
    gane, Jun 6, 2006
    #3
  4. gane wrote:
    > Hi,
    >
    > I am creating datagrid bound column dynamically and need to check if a
    > datagrid column already exists?Is there a way to check this?
    >

    Dynamically created columns do not persist between page loads so I'm not
    sure why you need to check.You should only dynamically create and add
    columns to a datagrid in the Page_Init event. From online help:

    The DataGrid control does not store the contents of its Columns
    collection into the view state. To add or remove a column dynamically,
    you must programmatically add or remove the column everytime the page is
    refreshed. Provide a Page_Init function that adds or removes the column
    before the DataGrid control's state is reload and the control is
    rebuilt. Otherwise, the changes to the Columns collection are not
    reflected in the DataGrid control when it is displayed.
    Note Although you can programmatically add columns to or remove
    columns from the Columns collection of the DataGrid control, it is
    easier to list the columns statically and then use the Visible property
    to display or hide each column.



    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Jun 6, 2006
    #4
  5. gane

    gane Guest

    I am using sort functionality on the datagrid, which is not firing if i dont
    have the datagrid binded in pageload.
    so i need to rebind twice in pageload and onsortcommand, which creates the
    dynamic bound columns twice.
    But now i clearing the grid, instead of finding a way to check for existing
    columns. Now it works.

    Thanks
    Gane
    "Bob Barrows [MVP]" <> wrote in message
    news:...
    > gane wrote:
    >> Hi,
    >>
    >> I am creating datagrid bound column dynamically and need to check if a
    >> datagrid column already exists?Is there a way to check this?
    >>

    > Dynamically created columns do not persist between page loads so I'm not
    > sure why you need to check.You should only dynamically create and add
    > columns to a datagrid in the Page_Init event. From online help:
    >
    > The DataGrid control does not store the contents of its Columns
    > collection into the view state. To add or remove a column dynamically,
    > you must programmatically add or remove the column everytime the page is
    > refreshed. Provide a Page_Init function that adds or removes the column
    > before the DataGrid control's state is reload and the control is
    > rebuilt. Otherwise, the changes to the Columns collection are not
    > reflected in the DataGrid control when it is displayed.
    > Note Although you can programmatically add columns to or remove
    > columns from the Columns collection of the DataGrid control, it is
    > easier to list the columns statically and then use the Visible property
    > to display or hide each column.
    >
    >
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
     
    gane, Jun 6, 2006
    #5
    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. Replies:
    2
    Views:
    6,493
  2. MattB
    Replies:
    2
    Views:
    16,386
    MattB
    Nov 11, 2005
  3. Totan
    Replies:
    0
    Views:
    1,033
    Totan
    Apr 17, 2006
  4. Chris
    Replies:
    2
    Views:
    4,520
    Chris
    May 10, 2006
  5. Ulf Meinhardt
    Replies:
    8
    Views:
    6,226
Loading...

Share This Page