manipulating datagrid at runtime

Discussion in 'ASP .Net Datagrid Control' started by KK, Jan 11, 2004.

  1. KK

    KK Guest

    Hi

    I use datagrid webcontrol on my webform. Curently I execute
    stored procedures, fill a dataset, then set the datasource property
    of the datagrid to show the data. What I want to know is;

    I want to hide/remove certain columns after binding.
    but if i use datagrid.columns[0].visible=false it doesn't work
    anyway it shows 0 for column count. Because I want to hide
    the tables primary key column.

    So basicaly, how can I programaticaly add/remove/hide columns
    and bind my dataset? .Net help regarding this binding wasn't very
    helpfull.

    I do not want to add columns and bind them at design time.
    Everything, should be able to setup at run time and assign the
    dataset.

    thanks
    KK
     
    KK, Jan 11, 2004
    #1
    1. Advertising

  2. KK

    Alvin Bruney Guest

    autogenerated columns aren't added to the column collection at runtime which
    is why the count is returning zero. You will need to remove these columns in
    either the itemcreated or itemdatabound event handlers. The column layout
    will follow the order of your query select clause.

    Consider select A, B, C from [snip]
    Creates an autogenerated column where index 0, 1, 2 map directly to A, B, C.
    To remove column C you would need the following code:
    e.Item.Cells[2].Visible = false;

    --
    Regards,
    Alvin Bruney
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "KK" <> wrote in message
    news:...
    > Hi
    >
    > I use datagrid webcontrol on my webform. Curently I execute
    > stored procedures, fill a dataset, then set the datasource property
    > of the datagrid to show the data. What I want to know is;
    >
    > I want to hide/remove certain columns after binding.
    > but if i use datagrid.columns[0].visible=false it doesn't work
    > anyway it shows 0 for column count. Because I want to hide
    > the tables primary key column.
    >
    > So basicaly, how can I programaticaly add/remove/hide columns
    > and bind my dataset? .Net help regarding this binding wasn't very
    > helpfull.
    >
    > I do not want to add columns and bind them at design time.
    > Everything, should be able to setup at run time and assign the
    > dataset.
    >
    > thanks
    > KK
    >
    >
     
    Alvin Bruney, Jan 11, 2004
    #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. =?Utf-8?B?RGF2aWQgVGlsbWFu?=

    Manipulating Datagrid Cells

    =?Utf-8?B?RGF2aWQgVGlsbWFu?=, Jul 20, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,164
    Eliyahu Goldin
    Jul 21, 2005
  2. Maarten

    manipulating datagrid client-side...

    Maarten, Mar 27, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    2,036
    Maarten
    Mar 27, 2006
  3. Timo Nentwig

    manipulating classes during runtime

    Timo Nentwig, Jul 14, 2003, in forum: Java
    Replies:
    2
    Views:
    408
    Sandip Chitale
    Jul 15, 2003
  4. Hal Vaughan
    Replies:
    11
    Views:
    1,197
    Gordon Beaton
    May 22, 2006
  5. Homer J. Simpson

    Manipulating style at runtime?

    Homer J. Simpson, Aug 9, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    474
    Homer J. Simpson
    Aug 10, 2007
Loading...

Share This Page