Listview ItemCommand

Discussion in 'ASP .Net Web Controls' started by Tom, Jul 20, 2009.

  1. Tom

    Tom Guest

    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?

    <asp:ListView ID="ListViewItemRates" runat="server"

    DataKeyNames="ItemID" OnItemDataBound="ListViewItemRates_ItemDataBound">
    Tom, Jul 20, 2009
    1. Advertisements

  2. 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

    private void ListViewRates_ItemCommand(object sender,
    ListViewCommandEventArgs e)

    Coskun Sunali [MVP], Jul 22, 2009
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.