Link to home
Start Free TrialLog in
Avatar of jookymaster
jookymaster

asked on

ASP.NET LisItem Attributes.Add does not work

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.
ASKER CERTIFIED SOLUTION
Avatar of mantarae
mantarae

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jookymaster
jookymaster

ASKER

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.
I hope they fix that and all the other little bugs, without making new ones. :)  Good luck.