Solved

ASP.NET LisItem Attributes.Add does not work

Posted on 2004-08-03
3
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JQuery Autocomplete Tag AJAX (Need nice script) 11 57
Set time on Session (ASP) 14 30
Sending ASP to server side 8 31
Display if field is NOT "" or NOT null 6 22
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…

756 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