如何在 .NET 中枚举单选按钮列表?

发布于 2024-07-18 07:19:16 字数 26 浏览 7 评论 0原文

如何在 .NET 中枚举单选按钮列表?

How can I enumerate a radiobuttonlist in .NET?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

信仰 2024-07-25 07:19:16
foreach (ListItem item in RadioButtonList1.Items)
{
    if (item .Selected == true)
    {
       Response.Write("You selected " + rbtn.Text);
    }
}
foreach (ListItem item in RadioButtonList1.Items)
{
    if (item .Selected == true)
    {
       Response.Write("You selected " + rbtn.Text);
    }
}
饮惑 2024-07-25 07:19:16

不太确定你在这里问什么 - 但如果你只是想枚举这些项目,它...

foreach (var item in MyRbl.Items)
{
   // do something with the current item.
}

如果你想获取值,只需使用 .SelectedValue

如果你想在客户端执行此操作获取选定的值 - 您可以使用 jQuery 来获取选定的值...

var selected = jQuery('#<%= MyRbl.ClientID %> input:checked').val();

Not really sure what you're asking here - but if you just want to enumerate thru the items, its...

foreach (var item in MyRbl.Items)
{
   // do something with the current item.
}

If you're trying to get the value, just use .SelectedValue

If you're trying to do it client side to get the selected value - you could use jQuery to get the selected value...

var selected = jQuery('#<%= MyRbl.ClientID %> input:checked').val();
难忘№最初的完美 2024-07-25 07:19:16

RadioButtonList.Items 是一个实现 IEnumerable 的 ListItemCollection。

RadioButtonList.Items is a ListItemCollection which implements IEnumerable.

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