Ahh my bad. forgot to do Foreach loop. Thank you for the help.
But it´s still not solved. Becuse I have 2 ListViews.
And it works only for the first ListView.
This is the code for ListView1 and it works.
foreach (ListViewItem item in ListView1.Items)
{
Label lbl = item.FindControl("lblUserName") as Label;
if (User.Identity.Name == lbl.Text.ToLower())
{
item.FindControl("EditButton").Visible = true;
}
else
{
item.FindControl("EditButton").Visible = false;
}
}
This code is for ListView2 and dosent work. Becuse ListView2.Items cant get any Items. Count = 0, all the time
foreach (ListViewItem item in ListView2.Items)
{
Label lbl = item.FindControl("lblUserName") as Label;
if (User.Identity.Name == lbl.Text.ToLower())
{
item.FindControl("EditButton").Visible = true;
}
else
{
item.FindControl("EditButton").Visible = false;
}
}
How can I fix it? Really stange. Becuse ListView1 is working like a charm.