ListItem.Attributes.Add not working

青春壹個敷衍的年華 提交于 2019-12-11 03:14:47

问题


I am trying to add a custom attribute to list item but it is not adding it

My code is this

ListItem item = new ListItem(teamMemberGroup.Name, teamMemberGroup.ID);
item.Attributes.Add("teammembergroup", "true");

ddlTeamGroups.Items.Add(item);
ddlTeamGroups1.Items.Add(item);

It is only adding option text and value in the Html but no attributes! My dropdown is inside an update panel but I don't think update panel is making something wrong as I am not looking for postback but it is only about the very first page load loading

Any idea?


回答1:


The attributes you add using

item.Attributes.Add("teammembergroup", "true");

will be added to the listitem only for client side it doesn't maintain its Attribute collection for the server side. If you want to have a look at the added attribute you can go to "view source" of your page & can see the added attribute there in to your rendered drop down list control.



来源:https://stackoverflow.com/questions/10977378/listitem-attributes-add-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!