Solved

ASP.NET LisItem Attributes.Add does not work

Posted on 2004-08-03
3
289 Views
Last Modified: 2008-01-09
I am binding a datasource to a CheckBoxList, and in the list of options I have a "None of these Apply to me" option, which is drawn from the datasource (i.e. so no, I cannot simply add a separate checkbox to do this, it must be implemented in the checkboxlist). What i tried to do is the following:

** the variable 'List' is the CheckBoxList
private override void OnPreRender(EventArgs e)
{
    //since the N/A option is always last
    ListItem na = List.Items[List.Items.Count - 1];
    na.Attributes.Add("onclick", "javascript:_doPostBack(//client id generated here));
}

--the onclick attribute is never added..this works flawlessly with a separate checkbox, why does the Attributes.Add method never work with ListItems?? This is extremely annoying, I can't understand why this would not have been implemented for listitems.
0
Comment
Question by:jookymaster
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
mantarae earned 500 total points
ID: 11705117
Looks like there is a bug when it comes to adding any kind of attributes with the dropdownlist and radiobuttonlist, the article doesn't include checkbox list, but my guess is that it also affects the checkboxlist.  

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q309338
0
 

Author Comment

by:jookymaster
ID: 11705197
ahh, yea it looks like that same concept could be easily applied to a checkboxlist, thanks for finding that article for me, I hope they fixed that bug in ASP.NET v2.
0
 
LVL 7

Expert Comment

by:mantarae
ID: 11705365
I hope they fix that and all the other little bugs, without making new ones. :)  Good luck.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now