回发时是否可以维护 ListItem 上添加的属性?

发布于 2024-12-16 12:06:43 字数 329 浏览 4 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍景流年 2024-12-23 12:06:43

回发后属性将丢失。下面的问题链接到 博客文章,其中包含将属性保留到视图状态的代码,但该代码是用 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文