Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Adding Attribute to ListItem

  Asked By: Lorenzo    Date: Jul 18    Category: Asp.net    Views: 1953
  

I am trying add an attribute to ListItem object. The ListItem is part of a CheckBoxList. But, the added attribute never gets rendered. Any clue?



ListItem li = new ListItem("name","value");

accsCheckList.Add(li); //accsCheckList is the CheckBoxList

accsCheckList.Items[i].Attributes.Add("onClick","return checkPIME(this);");

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Ujala Hashmi     Answered On: Jul 18

Attributes aren't written out for each Item.

Can't you add  the onClick to the CBL it-self and loop thru the elements in JS ??

CheckBoxList1.Attributes["onClick"] = "return checkPIME(this);";

-or-

You could make a control(inherit from CBL) and write out the attributes  for each element I guess.

I did that for a ListBox to show the color attrib.

Sample: www.gotdotnet.com/.../keywordsrch.aspx%20with%20color%20attribute

 
Answer #2    Answered By: Robin Bailey     Answered On: Jul 18

Yes, I am using the first option and using JS event to check which checkbox was clicked.

 
Didn't find what you were looking for? Find more on Adding Attribute to ListItem Or get search suggestion and latest updates.




Tagged: