从中继器项目检索数据

本文关键字:数据 检索 项目 中继器 | 更新日期: 2023-09-27 18:26:39

我有以下中继器:

<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>

我试着循环浏览每一项,找到一个选中单选按钮的项目。如果选中了单选按钮,我想检查其值(Accept或Reject)并检索数据(Eval Date、Hours等),然后将其发送到另一个方法以添加到数据库中。你能帮我吗,到目前为止的代码:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    foreach (RepeaterItem item in RptLeaveRequests.Items)
            {
            }
}

从中继器项目检索数据

您使用<asp:RadioButtonList>,但在代码隐藏中,您转换为RadioButton
尝试这样,

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