简体   繁体   English

从Repeater项中检索数据

[英]Retrieve Data from Repeater item

I have the following Repeater: 我有以下中继器:

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

Am I trying to loop through each item, find one where the radio button is checked. 我是否要遍历每个项目,找到选中单选按钮的项目? If a radio button is checked i want to then check its value (Accept or Reject) and retrieve the data (Eval Date,Hours etc) and send it to another method to add to the database. 如果选中了单选按钮,则我想检查其值(接受或拒绝)并检索数据(评估日期,小时等)并将其发送到另一种方法以添加到数据库中。 Can you please help me out, code so far: 到目前为止,您能否帮我解决问题:

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

You use <asp:RadioButtonList> , but in your code behind , you cast as RadioButton . 您使用<asp:RadioButtonList> ,但在后面的代码中,将其转换为RadioButton
Try likes this , 尝试这样,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM