Access to hyperlink in listview in Itemtemplate
I'm trying to access a hyperlink
on my listview
. When the user logs in,
the hyperlink will show on my homepage. It doesn't show.
protected void lvtop6_ItemCommand(object sender, ListViewCommandEventArgs e)
{
ListView hlBuy = (ListView)lvtop6.FindControl("hlBuy");
if (User.Identity.IsAuthenticated==true)
{
hlBuy.Visible = true;
开发者_运维百科 }
else
{
hlBuy.Visible = false;
}
}
Please somebody advise me to figure out what is wrong with my code behind
It's not clear what you're trying to set visible: your Hyperlink or your ListView.
You've cast a control to type ListView, but your Hungarian notation seems to suggest that it's a hyperlink. Update your question with more details, and we can get it sorted out.
Does lvtop6_ItemCommand()
ever get called? Can you set a breakpoint in that code?
Meanwhile, try to simplify your 5 lines of code into 1:
hlBuy.Visible = User.Identity.IsAuthenticated;
Perhaps you need to cast your hyperlink:
HyperLink hlBuy = (HyperLink)lvtop6.FindControl("hlBuy");
I'm trying to set visible my Hyperlink in my listview(lvtop6) the reason of why I'm doing this is when a user logged in then the hyperlink (hlBuy) will appear on my homepage. I'm not sure about that event I'm using lvtop6_ItemCommand() because when I set breakpoint nothing happend I've tried Databound events either but it did'nt work.
精彩评论