我有以下中继器:
<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>
我是否尝试遍历每个项目,找到一个选中单选按钮的位置。如果选中单选按钮,我想检查其值(接受或拒绝)并检索数据(评估日期,小时等)并将其发送到另一个方法以添加到数据库。 你能帮我解决一下,到目前为止的代码:
protected void btnSubmit_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in RptLeaveRequests.Items)
{
}
}
答案 0 :(得分:1)
您使用的是<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;
}
}