对于 asp.net radiobuttonlist:通过 FindByValue 获取列表项并设置 Selected 属性不起作用?
可能是一个基本问题,但我有以下代码:
ListItem l = radiolist.Items.FindByValue(mediaTypeID.ToString());
if (l != null)
l.Selected = true;
else
radiolist.SelectedIndex = 0;
handleMediaTypeChanged();
在上面的代码中,我可以成功地从单选按钮列表中检索正确的项目,但是将项目设置为“选定”不起作用。 SelectedIndexChanged 事件不会触发,当我使用 handleMediaTypeChanged()
手动调用它时,单选按钮列表不会反映更改的索引。如果不是这样,正确的方法是什么?
Probably a basic question but I have the following code:
ListItem l = radiolist.Items.FindByValue(mediaTypeID.ToString());
if (l != null)
l.Selected = true;
else
radiolist.SelectedIndex = 0;
handleMediaTypeChanged();
In the above code, I can successfully retrieve the correct item from the radiobuttonlist, however setting the item to be Selected is not working. The SelectedIndexChanged event does not fire, and when I call it manually using handleMediaTypeChanged()
the radiobuttonlist does not reflect a changed index. What is the proper way if this isn't it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,只有当您从 UI 物理更改索引时才会触发 SelectedIndexChanged 事件。
你可以尝试这样的事情:
As far as I know, the SelectedIndexChanged event will only fire when you've physically changed the index from the UI.
You can try something like this: