can't get data to show with bound columns

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default can't get data to show with bound columns

    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 Guest

  2. Similar Questions and Discussions

    1. Dynamically data-bound columns versus asp:ButtonColumn
      I'm working on a small application where I'd like to have a select column in a DataGrid displaying a result set returned from a stored proc. ...
    2. bound columns of a datagrid
      i have a datagrid with few bound columns.i want to make the first column clickable.can i make a bound column clickable and write a handler for...
    3. Binding to bound columns
      I've been trying to figure out how to use the design time column creation of columns. I turn off AutoGenerateColumns and create the bound columns...
    4. DG-Edit-Loosing data; bound columns - pushbuttons; dataReader
      Dear Readers, I am using C# (vb examples will work for me too - i am vb progrmr). I created a dg (datagrid) with bound columns (hesistant to...
    5. iterate through bound columns
      Hello, I have several pages with datagrids, and I was thinking of writing a common excel function. I want to iterate through the columns of...
  3. #2

    Default Re: can't get data to show with bound columns

    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" <headware@aol.com> wrote in message
    news:e3f4b0ae.0307081851.166cac5@posting.google.co m...
    > 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 Guest

  4. #3

    Default Re: can't get data to show with bound columns

    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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    headware x Guest

  5. #4

    Default Re: can't get data to show with bound columns

    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" <headware@aol.com> wrote in message
    news:uurPQYeRDHA.704@tk2msftngp13.phx.gbl...
    > 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 [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Alvin Bruney Guest

  6. #5

    Default Re: can't get data to show with bound columns

    Gotcha, thanks for the help!

    "Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in message news:<efvD57nRDHA.2188@TK2MSFTNGP10.phx.gbl>...
    > 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" <headware@aol.com> wrote in message
    > news:uurPQYeRDHA.704@tk2msftngp13.phx.gbl...
    > > 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 [url]http://www.developersdex.com[/url] ***
    > > Don't just participate in USENET...get rewarded for it!
    headware Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139