回发时是否可以维护 ListItem 上添加的属性?
我正在 ASP 中为 CheckBoxList 控件生成 ListItems,但是当我执行类似以下操作时:
...
Dim newListItem As ListItem = New ListItem("RoleName")
newListItem.Attributes.Add("style", "color:blue;")
CheckBoxListControlToFill.Items.Add(newListItem)
...
“RoleName”从回发到回发都得到维护,但我的样式标记在第一次回发后被删除。如果我想保留这样的任何属性,是否需要在每次回帖时重新添加它?
I am generating ListItems for a CheckBoxList control in ASP, but when I do something like the following:
...
Dim newListItem As ListItem = New ListItem("RoleName")
newListItem.Attributes.Add("style", "color:blue;")
CheckBoxListControlToFill.Items.Add(newListItem)
...
"RoleName" is maintained from post back to post back, but my style tag is dropped after the first post back. If I want to keep any attribute like this, do I need to re-add it every post back?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回发后属性将丢失。下面的问题链接到 博客文章,其中包含将属性保留到视图状态的代码,但该代码是用 C# 编写的 -
DropDownList 中的 ListItems 属性在回发时丢失?
The attributes will be lost after a postback. The question below links to a blog post that contains code that will persist attributes to the view state, the code is in c# though -
ListItems attributes in a DropDownList are lost on postback?