Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > can't get data to show with bound columns

Reply
Thread Tools

can't get data to show with bound columns

 
 
headware
Guest
Posts: n/a
 
      07-09-2003
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
 
Reply With Quote
 
 
 
 
Alvin Bruney
Guest
Posts: n/a
 
      07-09-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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



 
Reply With Quote
 
 
 
 
headware x
Guest
Posts: n/a
 
      07-09-2003
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!
 
Reply With Quote
 
Alvin Bruney
Guest
Posts: n/a
 
      07-10-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!



 
Reply With Quote
 
headware
Guest
Posts: n/a
 
      07-10-2003
Gotcha, thanks for the help!

"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in message news:<(E-Mail Removed)>...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Columns not bound to DetailsView get set to NULL on update Nick Bennett ASP General 1 01-20-2008 02:17 PM
template columns and bound columns in gridview Vinki ASP .Net Web Controls 2 04-25-2007 04:22 PM
Get number of columns of a late bound GridView ctilly@gmail.com ASP .Net Web Controls 1 06-27-2006 12:53 PM
How to represent the data in a not bound control via bound control Mario Krsnic ASP .Net 0 06-23-2006 07:38 AM
DG-Edit-Loosing data; bound columns - pushbuttons; dataReader Ravichandran Mahalingam ASP .Net Datagrid Control 0 01-08-2004 10:28 PM



Advertisments