ListItem.Attributes.Add不工作 [英] ListItem.Attributes.Add not working

查看:558
本文介绍了ListItem.Attributes.Add不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加自定义属性列出项目但不将它添加

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

我的code是这个

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

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

这是唯一的选项,添加文本和值在HTML,但没有属性!
我的下拉列表是一个更新面板内,但我不认为更新面板正在什么不对,因为我不是在寻找回发,但它仅仅是对第一页载荷加载

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

任何想法?

推荐答案

您使用添加的属性。

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.

这篇关于ListItem.Attributes.Add不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆