CheckBoxList: Adding onclick javascript event to each ListItem.

Discussion in 'ASP .Net Web Controls' started by Jimmy [Used-Disks], Nov 24, 2003.

  1. How can I add an onclick client-side event to each ListItem in a
    CheckBoxList? I tried iterating each item and adding an onclick attribute:

    foreach(ListItem Item in this.MyCheckBoxList.Items){
    Item.Attributes.Add("onclick", "alert('test')");
    }

    Though the attributes get added (I can see them in the debugger, write them
    to a label, etcetera), they are not rendered to the page.

    Is there a simple workaround for this? Should I just use a repeater and do
    everything manually?

    Thanks -

    --
    -Jimmy
    Jimmy [Used-Disks], Nov 24, 2003
    #1
    1. Advertising

  2. Jimmy [Used-Disks]

    Sonali Guest

    Hello,
    I am curious, has anyone found a solution to this?
    Thanks,
    Sonali
    >-----Original Message-----
    >How can I add an onclick client-side event to each

    ListItem in a
    >CheckBoxList? I tried iterating each item and adding an

    onclick attribute:
    >
    >foreach(ListItem Item in this.MyCheckBoxList.Items){
    > Item.Attributes.Add("onclick", "alert('test')");
    >}
    >
    >Though the attributes get added (I can see them in the

    debugger, write them
    >to a label, etcetera), they are not rendered to the page.
    >
    >Is there a simple workaround for this? Should I just use

    a repeater and do
    >everything manually?
    >
    >Thanks -
    >
    >--
    >-Jimmy
    >
    >
    >.
    >
    Sonali, Dec 10, 2003
    #2
    1. Advertising

  3. "Sonali" <> wrote in message
    news:094301c3bf39$34099470$...
    > Hello,
    > I am curious, has anyone found a solution to this?


    Not that I know :(. I ended up using a repeater. If I can get around to it,
    I'll write a control which will allow this.

    > Thanks,
    > Sonali


    --
    -Jimmy
    Jimmy [Used-Disks], Dec 10, 2003
    #3
    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. Shaul Feldman
    Replies:
    4
    Views:
    13,328
    Shaul Feldman
    Apr 14, 2004
  2. JD
    Replies:
    5
    Views:
    11,649
    NetArchitect
    Aug 8, 2007
  3. Mad Scientist Jr
    Replies:
    2
    Views:
    440
    Mad Scientist Jr
    Jun 29, 2004
  4. CK
    Replies:
    0
    Views:
    3,803
  5. Jim in Arizona
    Replies:
    7
    Views:
    914
    Badass Scotsman
    Nov 22, 2006
Loading...

Share This Page