tags:

views:

26

answers:

2

What I'm trying to do is on page load display either of two controls based on how many items are in a datalist. For instance, if the datalist only contains 1 item I want it to display

Literal1.Visible = true;

If there is more than 1 item in the datalist, show

LiteralMulti.Visible = true;

Anyone know how to do this?

A: 

Check the Count of the Items property.

Literal1.Visible = myDataList.Items.Count == 1;

LiteralMulti.Visible = myDataList.Items.Count > 1;
Brandon
This will work too.
tking
+1  A: 

Use can simple do that in Page_Load method :

if(DataListName.Items.Count > 1)
{
    Literalmulti.Visible = true;
} 
else
{
    Literalsingle.Visible = true;
}
DEVMBM
Thats what I was looking for. Thank you.
tking
for some reason i'm having trouble getting this to work correctly. ts like it cant get the count of the datalist correctly. it displays the single literal on every load no matter how many items are in the datalist. if i use -1 then it shows the multi on every page. using 0 also shows single of every page.
tking
nevermind, i figured it out. just needed to move it out of the page_load and into the databound method - duh!
tking