C# 需要逐步查看静态创建的radiobuttonlist中的值

C# 需要逐步查看静态创建的radiobuttonlist中的值,c#,asp.net,C#,Asp.net,我继承了下表中的一些Asp.net代码。我需要逐步查找所有被选为“坏”的单选按钮,然后查找相关的columntext。以下是aspx代码: <table class="checklistTable" id="checkListTable" cellpadding="0" cellspacing="0" runat="server"> <!-- start of visual checks --> <tr> <td cols

我继承了下表中的一些Asp.net代码。我需要逐步查找所有被选为“坏”的单选按钮,然后查找相关的columntext。以下是aspx代码:

<table class="checklistTable" id="checkListTable" cellpadding="0" cellspacing="0" runat="server">
    <!-- start of visual checks -->
    <tr>
        <td colspan="4" class="sectionTitle">
            Visual Checks
        </td>
    </tr>
    <tr>
        <td class="columnRadioPictures">
            <asp:Image ID="Image1" runat="server" AlternateText="Ok" ImageUrl="../../images/checkmark.gif" />
            <asp:Image ID="Image2" runat="server" AlternateText="Bad" ImageUrl="../../images/xmark.gif" />
            <asp:Image ID="Image6" runat="server" AlternateText="N/A" ImageUrl="../../images/notapplicable.gif" />
        </td>
        <td class="columnText">
            &nbsp;
        </td>
        <td class="columnRadioPictures">
            <asp:Image ID="Image3" runat="server" AlternateText="Ok" ImageUrl="../../images/checkmark.gif" />
            <asp:Image ID="Image4" runat="server" AlternateText="Bad" ImageUrl="../../images/xmark.gif" />
            <asp:Image ID="Image5" runat="server" AlternateText="N/A" ImageUrl="../../images/notapplicable.gif" />
        </td>
        <td class="columnText">
            &nbsp;
        </td>
    </tr>
    <tr>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_MfgManual" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            MANUFACTURER'S MANUAL
        </td>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_Hoses" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            HOSES
        </td>
    </tr>
    <tr>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_DataPlate" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            DATA PLATE
        </td>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_TiresWheels" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            TIRES/WHEELS
        </td>
    </tr>
    <tr>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_WarningDecals" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            WARNING DECALS
        </td>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_Mirrors" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            MIRRORS
        </td>
    </tr>
    <tr>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_OverheadGuard" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            OVERHEAD GUARD
        </td>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_SeatBelt" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            SEAT BELT
        </td>
    </tr>
    <tr>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_MastAssembly" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            MAST AND BOOM ASSEMBLY
        </td>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_FireExtinguisher" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            FIRE EXTINGUISHER
        </td>
    </tr>
    <tr>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_LiftChainRoller" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            LIFT CHAINS/ROLLERS
        </td>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_FuelCap" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            FUEL CAP
        </td>
    </tr>
    <tr>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_Forks" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            FORKS/RAM
        </td>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_PropaneTank" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            PROPANE TANK
        </td>
    </tr>
    <tr>
        <td class="columnRadio">
            <asp:RadioButtonList ID="VC_HydraulicCylinders" RepeatDirection="Horizontal" runat="server">
                <asp:ListItem Value="Ok" Text="" />
                <asp:ListItem Value="Bad" Text="" />
                <asp:ListItem Value="N/A" Text="" />
            </asp:RadioButtonList>
        </td>
        <td class="columnText">
            HYDRAULIC CYLINDERS
        </td>
    </tr>
</table>

目视检查
制造商手册
软管
铭牌
轮胎/车轮
警告贴纸
镜子
头顶护板
安全带
桅杆和吊杆组件
灭火器
提升链/滚轮
燃料帽
叉/闸板
丙烷罐
液压缸
我尝试了以下代码,但没有读取radiobutton的值:

foreach (Control ctrl in checkListTable.Controls)
{
    foreach (Control tblCell in ctrl.Controls)
    {
        foreach (Control radioBtn in tblCell.Controls)
        {
            strCtrl = radioBtn.GetType().ToString();
            if (radioBtn is RadioButtonList)
            {
                RadioButtonList rbl = (RadioButtonList)ctrl;

                for (int i = 0; i < rbl.Items.Count; i++)
                {
                    if (rbl.Items[i].Value.ToString() == "Bad")
                    {
                        //get the text value of the column text

                    }
                }
            }
        }
    }
}
foreach(checkListTable.Controls中的控件ctrl)
{
foreach(ctrl.Controls中的控制tblCell)
{
foreach(tblCell.Controls中的控制无线电BTN)
{
strCtrl=radioBtn.GetType().ToString();
如果(radioBtn是RadioButtonList)
{
RadioButtonList rbl=(RadioButtonList)ctrl;
对于(int i=0;i

提前谢谢

您可以使用Jimmy在中提供的ControlFinder获取每个RadioButtonList的
ID
SelectedValue
属性:

ControlFinder<RadioButtonList> radioButtonLists = new ControlFinder<RadioButtonList>();
radioButtonLists.FindChildControlsRecursive(checkListTable);

foreach (RadioButtonList rbl in radioButtonLists.FoundControls)
{
    string id = rbl.ID;
    string value = rbl.SelectedValue;
    ...
}
ControlFinder radioButtonLists=新建ControlFinder();
RadioButtonList.FindChildControlsRecursive(检查列表表);
foreach(RadioButtonList.FoundControls中的RadioButtonList rbl)
{
字符串id=rbl.id;
字符串值=rbl.SelectedValue;
...
}

但是,相邻单元格的文本(例如
制造商手册
)不易访问,并且与相应RadioButtonList的连接不明显。

您可以使用Jimmy in提供的ControlFinder获取每个RadioButtonList的
ID
SelectedValue
属性:

ControlFinder<RadioButtonList> radioButtonLists = new ControlFinder<RadioButtonList>();
radioButtonLists.FindChildControlsRecursive(checkListTable);

foreach (RadioButtonList rbl in radioButtonLists.FoundControls)
{
    string id = rbl.ID;
    string value = rbl.SelectedValue;
    ...
}
ControlFinder radioButtonLists=新建ControlFinder();
RadioButtonList.FindChildControlsRecursive(检查列表表);
foreach(RadioButtonList.FoundControls中的RadioButtonList rbl)
{
字符串id=rbl.id;
字符串值=rbl.SelectedValue;
...
}
但是,相邻单元格的文本(例如
制造商手册
)不易访问,并且与相应RadioButton列表的连接不明显