Listview ItemCommand

T

Tom

I have a listview and I'm creating some image link buttons in the item place
holder. If a guest is logged in the app I add some javascript so when they
click the link buttons I just change some client stuff. If the app is run
by admin I want to implement the ItemCommand and execute some server code
when the user clicks the link button.

If I set up my listview in my .aspx like below, it's fine for my admin mode
but I want to default for guest mode (w/o the OnItemCommand) and let the
javascript execute - so I've removed the OnItemCommand.

How can I add the OnItemCommand="ListViewRates_ItemCommand" in my c# on the
page_load when I'm loading for admin mode?

Thanks...Tom
<asp:ListView ID="ListViewItemRates" runat="server"
OnItemCommand="ListViewRates_ItemCommand"

DataKeyNames="ItemID" OnItemDataBound="ListViewItemRates_ItemDataBound">
 
C

Coskun Sunali [MVP]

Hi Tom,

It would be like below:

private bool IsAdmin()
{
return true; // or false depending on your business
}

protected void Page_Load(object sender, EventArgs e)
{
if (this.IsAdmin())
{
ListViewItemRates.ItemCommand += new
EventHandler<ListViewCommandEventArgs>(this.ListViewRates_ItemCommand);
}
}

private void ListViewRates_ItemCommand(object sender,
ListViewCommandEventArgs e)
{

}
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top