【问题标题】:Retrieve Data from Repeater item从中继器项中检索数据
【发布时间】:2013-08-08 15:13:05
【问题描述】:

我有以下中继器:

<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)
            {
            }
}

【问题讨论】:

  • 这是理解中继器的非常简单的例子:aspdotnet-suresh.com/2012/01/…
  • 您使用 &lt;asp:RadioButtonList&gt; ,但在您的代码后面,您转换为 RadioButton

标签: c# asp.net radio-button repeater


【解决方案1】:

您使用 &lt;asp:RadioButtonList&gt; ,但在您的代码后面,您转换为 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;
                     }
           }

【讨论】:

  • 你能检查更新吗?当我尝试使用例如 Convert.ToString((Label)item.FindControl("Date")) 检索数据时,它返回一个空字符串
  • FindControl("Date")) ?我没有看到任何名称为 Date 的控件。你的意思是lblDate 吗?转你的名字点赞Convert.ToString((Label)item.FindControl("lblDate"))
猜你喜欢
  • 1970-01-01
  • 2014-05-21
  • 1970-01-01
  • 1970-01-01
  • 2018-03-27
  • 1970-01-01
  • 2016-02-20
  • 2020-07-29
  • 1970-01-01
相关资源
最近更新 更多