Hiding datalistitems

T

tshad

I am trying to hide all my datalistitems, which contain labels, textboxes a
datagrid, etc. I want to show each datalist item one at a time on the page
as the user pages through it.

I tried:

for each oItem as DataListItem in DataList1.Items
oItem.Visible = false

And that doesn't seem to work.

I can set the whole datalist.visible to false and it hides it fine.

Why doesn't the Datalistitem.visible = false work? It is supposed to be a
property of the datalistitem.

Thanks,

Tom
 
J

Jc Morin

Hi Tom,

The visible property inherits from the Control object, this property is
usually used to hide completely a control.
Setting the property to every items seems logical to me also to hide/show
them but It seems that your right, it doesn't work...

However I found something that may interest you.

I've try this in the ItemDataBound methods:
e.Item.Parent.Visible = False

And the visible property seems to works.

Lets me know if that solve your problem.
 
T

tshad

Jc Morin said:
Hi Tom,

The visible property inherits from the Control object, this property is
usually used to hide completely a control.
Setting the property to every items seems logical to me also to hide/show
them but It seems that your right, it doesn't work...

However I found something that may interest you.

I've try this in the ItemDataBound methods:
e.Item.Parent.Visible = False

And the visible property seems to works.

Lets me know if that solve your problem.

Not sure how to make this work.

The databound event only happens once per row as the data comes in.

In my case,

I want to be able make the datalistitem visible and not visible depending on
the user. All the data is there already.

I tried to put a <div id="dataitem" runat="server"> around the data inside
the ItemTemplate, but got a compiler error trying that.

The only way I have been able to figure out how to do it is to make each
object in the datalist "not visible" and then make the ones in the datalist
I am dealing with visible (and of course the list that was visible needs to
be made invisible).

Would have been easier and cleaner to be able to use the visible field of
the datalistitem as MS documentation says you can.

Thanks,

Tom
 
T

tshad

I did find that I can do the <div id=name visible=false runat="server">. I
needed to do this instead of making each object invisible as the datalist
control has html table/tr/td code in it that would still be visible.

The problem is that if I use the div and make it invisible, I seem to lose
the other object forever. I tried to make the div visible (which works
fine), but the objects (grid, labels etc) are not there.

Here is the control tree from my trace.warn:
****************************************************
DataList1System.Web.UI.WebControls.DataList113976
DataList1:_ctl0System.Web.UI.WebControls.DataListItem290
DataList1:_ctl0:_ctl0System.Web.UI.LiteralControl100
DataList1:_ctl0:dataListItemDivSystem.Web.UI.HtmlControls.HtmlGenericControl032
DataList1:_ctl0:_ctl1System.Web.UI.LiteralControl00
DataList1:_ctl0:ExpandButtonSystem.Web.UI.WebControls.ImageButton00
DataList1:_ctl0:_ctl2System.Web.UI.LiteralControl00
DataList1:_ctl0:CollapseButtonSystem.Web.UI.WebControls.ImageButton00
DataList1:_ctl0:_ctl3System.Web.UI.LiteralControl00
DataList1:_ctl0:positionIDSystem.Web.UI.WebControls.Label032
DataList1:_ctl0:_ctl4System.Web.UI.LiteralControl00
DataList1:_ctl0:QuestionUniqueSystem.Web.UI.WebControls.Label028
DataList1:_ctl0:_ctl5System.Web.UI.LiteralControl00
DataList1:_ctl0:QuestionTypeSystem.Web.UI.WebControls.Label032
DataList1:_ctl0:_ctl6System.Web.UI.LiteralControl00
DataList1:_ctl0:QuestionSystem.Web.UI.WebControls.Label084
DataList1:_ctl0:_ctl7System.Web.UI.LiteralControl00
DataList1:_ctl0:DataGrid1System.Web.UI.WebControls.DataGrid0136
DataList1:_ctl0:dataGridBrSystem.Web.UI.HtmlControls.HtmlGenericControl00
DataList1:_ctl0:_ctl8System.Web.UI.LiteralControl00
DataList1:_ctl0:submitQuestionSystem.Web.UI.WebControls.Button00
DataList1:_ctl0:_ctl9System.Web.UI.LiteralControl00
DataList1:_ctl0:_ctl10System.Web.UI.LiteralControl190
DataList1:_ctl1System.Web.UI.WebControls.DataListItem190
DataList1:_ctl1:_ctl1System.Web.UI.LiteralControl100
DataList1:_ctl1:_ctl0System.Web.UI.HtmlControls.HtmlGenericControl00
DataList1:_ctl1:_ctl2System.Web.UI.LiteralControl90
DataList1:_ctl2System.Web.UI.WebControls.DataListItem290
DataList1:_ctl2:_ctl0System.Web.UI.LiteralControl100
DataList1:_ctl2:dataListItemDivSystem.Web.UI.HtmlControls.HtmlGenericControl032
DataList1:_ctl2:_ctl1System.Web.UI.LiteralControl00
DataList1:_ctl2:ExpandButtonSystem.Web.UI.WebControls.ImageButton00
DataList1:_ctl2:_ctl2System.Web.UI.LiteralControl00
DataList1:_ctl2:CollapseButtonSystem.Web.UI.WebControls.ImageButton00
DataList1:_ctl2:_ctl3System.Web.UI.LiteralControl00
DataList1:_ctl2:positionIDSystem.Web.UI.WebControls.Label032
DataList1:_ctl2:_ctl4System.Web.UI.LiteralControl00
DataList1:_ctl2:QuestionUniqueSystem.Web.UI.WebControls.Label028
DataList1:_ctl2:_ctl5System.Web.UI.LiteralControl00
DataList1:_ctl2:QuestionTypeSystem.Web.UI.WebControls.Label032
DataList1:_ctl2:_ctl6System.Web.UI.LiteralControl00
DataList1:_ctl2:QuestionSystem.Web.UI.WebControls.Label060
DataList1:_ctl2:_ctl7System.Web.UI.LiteralControl00
DataList1:_ctl2:DataGrid1System.Web.UI.WebControls.DataGrid0136
DataList1:_ctl2:dataGridBrSystem.Web.UI.HtmlControls.HtmlGenericControl00
DataList1:_ctl2:_ctl8System.Web.UI.LiteralControl00
DataList1:_ctl2:submitQuestionSystem.Web.UI.WebControls.Button00
DataList1:_ctl2:_ctl9System.Web.UI.LiteralControl00
DataList1:_ctl2:_ctl10System.Web.UI.LiteralControl190
DataList1:_ctl3System.Web.UI.WebControls.DataListItem190
DataList1:_ctl3:_ctl1System.Web.UI.LiteralControl100
DataList1:_ctl3:_ctl0System.Web.UI.HtmlControls.HtmlGenericControl00
DataList1:_ctl3:_ctl2System.Web.UI.LiteralControl90
**********************************************************************************

Every other datalistitems show the controls and the other only show 3
controls.(I think because of the AlternateRow).

This is after I set all the div to visible=true.

So obviously this is not going to work.

It would have been so easy had MS property worked correctly.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top