C# 从中继器项检索数据

C# 从中继器项检索数据,c#,asp.net,radio-button,repeater,C#,Asp.net,Radio Button,Repeater,我有以下中继器: <asp:Repeater ID="RptLeaveRequests" runat="server" onitemdatabound="RptLeaveRequests_ItemDataBound"> <ItemTemplate> <table id="tableItem" runat="server"> <tr> <td style="width:

我有以下中继器:

<asp:Repeater ID="RptLeaveRequests" runat="server" 
        onitemdatabound="RptLeaveRequests_ItemDataBound">
<ItemTemplate>
    <table id="tableItem" runat="server">
        <tr>
                <td style="width: 100px;">
                    <asp:Label ID="lblDate" runat="server" Text='<%#Eval("Date", "{0:dd/M/yyyy}") %>'></asp:Label>
                </td>
                <td style="width: 100px;">
                    <asp:Label ID="lblHours" runat="server" Text='<%#Eval("Hours") %>'></asp:Label>
                </td>
                <td style="width: 200px;">
                    <asp:Label ID="lblPeriod" runat="server" Text='<%#Eval("AMorPM") %>'></asp:Label>
                </td>
                <td style="width: 200px; font-size:10px;">
                    <asp:Label ID="lblNote" runat="server" Text='<%#Eval("Note") %>'></asp:Label>
                </td>
                <td style="50px">
                    <asp:RadioButtonList ID="rbtVerified" runat="server" >
                        <asp:ListItem Value="1">Accept</asp:ListItem>
                        <asp:ListItem Value="2">Reject</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
                <td>
                    <asp:TextBox ID="txtNotes" runat="server" ></asp:TextBox>
                </td>
            </tr>
    </table>
</ItemTemplate>
</asp:Repeater>
您使用的是
,但在代码隐藏中,您使用的是
单选按钮

试着像这样

           foreach (RepeaterItem item in RptLeaveRequests.Items)
           { 
                var rdbList = item.FindControl("rbtVerified") as RadioButtonList;
                switch(rdbList.SelectedValue)
                     {
                      case "1":
                        //Accept
                      break;
                      case "2":
                       //Reject
                      break;
                     }
           }

这是理解repeater的一个非常简单的例子:您使用
,但在代码隐藏中,您使用的是
RadioButton
!你能检查一下吗?当我尝试使用例如Convert.ToString((Label)item.FindControl(“日期”)检索数据时,它返回一个空字符串
FindControl(“日期”)
?我没有看到任何名为
Date
的控件。你是说lblDate
lblDate
?将您的名字转换为Convert.ToString((标签)item.FindControl(“lblDate”))
           foreach (RepeaterItem item in RptLeaveRequests.Items)
           { 
                var rdbList = item.FindControl("rbtVerified") as RadioButtonList;
                switch(rdbList.SelectedValue)
                     {
                      case "1":
                        //Accept
                      break;
                      case "2":
                       //Reject
                      break;
                     }
           }