can't get data to show with bound columns

Discussion in 'ASP .Net Datagrid Control' started by headware, Jul 9, 2003.

  1. headware

    headware Guest

    I'm trying to create a DataGrid filled with values from a DataSet and
    I want the user to be able to show and hide whichever columns they
    choose. I have a dropdown list box filled with the column names so the
    user can select a column name and hit a button to hide or show it.
    I originally tried to use an unbound DataGrid with autogenerated
    columns, however the DataGrid.Columns collection is empty when all the
    columns are autogenerated (which seems unnecessarily unfriendly to me,
    but that's beside the point). As a result the table displayed the
    correct data but I had no way to access the columns in order to hide
    them.
    So I tried to set up explicitly bound columns. I changed the
    "autogenerate columns" property to false and specified the same amount
    of columns in the DataGrid as the DataSet was returning. Now, I have
    the opposite functionality. I can get the columns to show and hide but
    the data isn't showing up in the grid. It has no rows. What's going on
    here? Is there any better way to do this? It's driving me nuts.

    Thanks
     
    headware, Jul 9, 2003
    #1
    1. Advertising

  2. headware

    Alvin Bruney Guest

    go back to the autogenerated column. here is the code to hide it
    you need to do this in the itemdatabound event handler
    foreach(string toHide in ListBox1)

    {

    if(toHide != " ")

    e.Item.Cells[int.Parse(toHide)].Visible = false;

    }

    toHide would be an index of the selected item instead of the string because
    Cells only takes an int.

    happy camping



    "headware" <> wrote in message
    news:...
    > I'm trying to create a DataGrid filled with values from a DataSet and
    > I want the user to be able to show and hide whichever columns they
    > choose. I have a dropdown list box filled with the column names so the
    > user can select a column name and hit a button to hide or show it.
    > I originally tried to use an unbound DataGrid with autogenerated
    > columns, however the DataGrid.Columns collection is empty when all the
    > columns are autogenerated (which seems unnecessarily unfriendly to me,
    > but that's beside the point). As a result the table displayed the
    > correct data but I had no way to access the columns in order to hide
    > them.
    > So I tried to set up explicitly bound columns. I changed the
    > "autogenerate columns" property to false and specified the same amount
    > of columns in the DataGrid as the DataSet was returning. Now, I have
    > the opposite functionality. I can get the columns to show and hide but
    > the data isn't showing up in the grid. It has no rows. What's going on
    > here? Is there any better way to do this? It's driving me nuts.
    >
    > Thanks
     
    Alvin Bruney, Jul 9, 2003
    #2
    1. Advertising

  3. headware

    headware x Guest

    Well, the DataGrid.Items property doesn't have a Cells property so I'm
    not sure what you mean. Do you mean the DataGrid.Columns collection? If
    so, it still doesn't contain anything by the time execution gets to the
    ItemDateBound event, so it's pretty much the same situation as before.
    By the way, I'm doing this in C#, not VB if that matters.

    Thanks


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    headware x, Jul 9, 2003
    #3
  4. headware

    Alvin Bruney Guest

    you need to do this in the itemdatabound event handler.
    For every row that gets bound in a grid, the itemdatabound event fires which
    implies it must have something to bind to. If you look at my posted code, I
    said e.Items.Cells. e comes from the itemdatabound event handler - it's part
    of the event args.

    "headware x" <> wrote in message
    news:...
    > Well, the DataGrid.Items property doesn't have a Cells property so I'm
    > not sure what you mean. Do you mean the DataGrid.Columns collection? If
    > so, it still doesn't contain anything by the time execution gets to the
    > ItemDateBound event, so it's pretty much the same situation as before.
    > By the way, I'm doing this in C#, not VB if that matters.
    >
    > Thanks
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Alvin Bruney, Jul 10, 2003
    #4
  5. headware

    headware Guest

    Gotcha, thanks for the help!

    "Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com> wrote in message news:<>...
    > you need to do this in the itemdatabound event handler.
    > For every row that gets bound in a grid, the itemdatabound event fires which
    > implies it must have something to bind to. If you look at my posted code, I
    > said e.Items.Cells. e comes from the itemdatabound event handler - it's part
    > of the event args.
    >
    > "headware x" <> wrote in message
    > news:...
    > > Well, the DataGrid.Items property doesn't have a Cells property so I'm
    > > not sure what you mean. Do you mean the DataGrid.Columns collection? If
    > > so, it still doesn't contain anything by the time execution gets to the
    > > ItemDateBound event, so it's pretty much the same situation as before.
    > > By the way, I'm doing this in C#, not VB if that matters.
    > >
    > > Thanks
    > >
    > >
    > > *** Sent via Developersdex http://www.developersdex.com ***
    > > Don't just participate in USENET...get rewarded for it!
     
    headware, Jul 10, 2003
    #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. Mario Krsnic
    Replies:
    0
    Views:
    386
    Mario Krsnic
    Jun 23, 2006
  2. Ravichandran Mahalingam

    DG-Edit-Loosing data; bound columns - pushbuttons; dataReader

    Ravichandran Mahalingam, Jan 8, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    145
    Ravichandran Mahalingam
    Jan 8, 2004
  3. Replies:
    1
    Views:
    495
    Vadivel Kumar
    Jun 27, 2006
  4. Vinki

    template columns and bound columns in gridview

    Vinki, Apr 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    879
    Vinki
    Apr 25, 2007
  5. Nick Bennett
    Replies:
    1
    Views:
    206
    Bob Barrows [MVP]
    Jan 20, 2008
Loading...

Share This Page