ASP.net通过控制表中的循环 [英] ASP.net looping through controls in a table

查看:113
本文介绍了ASP.net通过控制表中的循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含了一堆动态创建的单选按钮列表的表,我尝试写code,将通过循环的单选按钮列表中的每一个,并得到所选项目的文本值。我有以下code

i have a table which contains a bunch of dynamically created radio button lists, im trying to write code which will loop through each one of the radio button list and get the text value of the selected item. i have the following code

   foreach ( Control ctrl in Table1.Controls)
    {
        if (ctrl is RadioButtonList)
        {
           //get the text value of the selected radio button 
        }
    }

但我被困在如何我能得到所选项目的价值,鉴于控制我。

but i am stuck on how i can get the value of the selected item for that given control.

推荐答案

试试这个:

foreach (Control ctrl in Table1.Controls)
{
    if (ctrl is RadioButtonList)
    {  
        RadioButtonList rbl = (RadioButtonList)ctrl;

        for (int i = 0; i < rbl.Items.Count; i++)
        {
            if (rbl.Items[i].Selected)
            {
                //get the text value of the selected radio button
                string value = rbl.Items[i].Text;
            }
        }
    }
}

要确定RadioButtonList控件选择的项目,通过Items集合迭代,集合中的测试每个项目的Selected属性。

To determine the selected items in the RadioButtonList control, iterate through the Items collection and test the Selected property of each item in the collection.

看看这里: RadioButtonList的Web服务器控件

这篇关于ASP.net通过控制表中的循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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