• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1430
  • Last Modified:

Checkboxlist item onclick JS

I am tryign everythign to set an onclick JS event for a checkboxlist item - wityh nothing happening?
ULCheckBoxList1.DataBind();
            foreach (ListItem li in ULCheckBoxList1.Items)
            {
                li.Attributes.Add("onclick", "javascript:alert('test');");
            }

Open in new window

0
tbaseflug
Asked:
tbaseflug
  • 4
  • 3
1 Solution
 
ajitha75Commented:
The code is correct. Maybe when the for loop is executed, there are no items in checkboxlist.
0
 
Chandan_GowdaCommented:
once the page is completely rendered,view the source of the web page.and cross check onclick attribute for checkbox's .
0
 
tbaseflugAuthor Commented:
OK - weird - I am databinding my cbl in the page load and then setting the OnDataBound to the below - but when I view the rendered source - nothing is there?
        foreach (ListItem li in ULCheckBoxList1.Items)
        {
            li.Attributes.Add("onclick", "javascript:alert('test');");
        } 

Open in new window

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ajitha75Commented:
Why in OnDataBound. You should do it in Page load itself.... after calling DataBind()

0
 
tbaseflugAuthor Commented:
even when I put it in the page load - I do not see it in the rendered html

            ULCheckBoxList2.DataBind();
            foreach (ListItem li in ULCheckBoxList1.Items)
            {
                li.Attributes.Add("onclick", "javascript:alert('test');");
            }
0
 
ajitha75Commented:
can you paste your complete code here?
0
 
tbaseflugAuthor Commented:
besides the above - this is it
                                    <asp:CheckBoxList  ID="ULCheckBoxList1" runat="server" CellPadding="0" CellSpacing="0"
                                        CssClass="colorCheck">
                                        <asp:ListItem id="aa"  >ICD9 Codes (2007 updates included): </asp:ListItem>
                                    </asp:CheckBoxList  >

Open in new window

0
 
ajitha75Commented:
You are not setting datasource.. then why do databind?
also if it is a static list, then you can add the onclick directly in the html code. why loop thru in the code behind?
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now