C# 获取当前“中的中继器标签”;“世界其他地区”;正在访问

C# 获取当前“中的中继器标签”;“世界其他地区”;正在访问,c#,asp.net,label,repeater,C#,Asp.net,Label,Repeater,我有以下中继器: <asp:Repeater ID="RptLeaveRequests" runat="server" onitemdatabound="RptLeaveRequests_ItemDataBound"> <ItemTemplate> <table id="tableItem" runat="server"> <tr> <td style="width: 100px;">

我有以下中继器:

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

我相信它不起作用,因为你找不到控制装置<如果找不到控件,code>FindControl将返回null;如果对象值为null,
Convert.ToString
将返回空字符串

从我看到的情况来看,您正在搜索错误的字符串ID。因此,它应该是
lblDate
,而不是
Date

如果您处于调试构建模式,请记住ASP.NET喜欢在运行时更改控件名称,因此“lblDate”控件可能实际上不是“lblDate”。因此,您可以尝试在浏览器上进行调试,并检查元素的ID是否为实际ID

此外,如果您想要标签的实际数据,您可能需要这样做(请注意
.Text
):


只是一个更新,我刚刚意识到如果您正在访问标签的文本属性,那么实际上不需要Convert.ToString,所以我更新了代码行。
 foreach (RepeaterItem item in RptLeaveRequests.Items)
            {
                var rdbList = item.FindControl("rbtVerified") as RadioButtonList;
                switch (rdbList.SelectedValue)
                {
                    case "1":
                        if (new LeaveLogic().AddLeaveEmployee(Convert.ToString((Label)item.FindControl("Date")), Convert.ToDouble((Label)item.FindControl("Hours")), Convert.ToString((Label)item.FindControl("AMorPM")), "Vacational Leave", Convert.ToInt32(Context.User.Identity.Name), Convert.ToString((Label)item.FindControl("Note")))
                        {
                            Response.Redirect(Request.RawUrl);
                        }
                        break;
((Label)item.FindControl("lblDate")).Text