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?

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

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

  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
    EventHandler<ListViewCommandEventArgs>(this.ListViewRates_ItemCommand);
    }
    }

    private void ListViewRates_ItemCommand(object sender,
    ListViewCommandEventArgs e)
    {

    }

    --
    Coskun Sunali
    Microsoft MVP - ASP.NET
    http://sunali.com
    http://propeople.dk


    "Tom" <> wrote in message
    news:eP6eO#...
    > 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">
    >
    >
     
    Coskun Sunali [MVP], Jul 22, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Natty Gur
    Replies:
    0
    Views:
    590
    Natty Gur
    Jun 30, 2003
  2. Jonas Nilsson

    ItemCommand Event fires twice

    Jonas Nilsson, Aug 1, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,093
    Jonas Nilsson
    Aug 1, 2003
  3. Mike

    DataGrid ItemCommand Event

    Mike, Oct 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    504
    Patrik Löwendahl
    Oct 24, 2003
  4. Steven
    Replies:
    4
    Views:
    1,561
    Steven
    Oct 25, 2003
  5. .
    Replies:
    0
    Views:
    745
Loading...

Share This Page