Asp.net 标签赢得';在页脚模板/Panel/SecurePanel/Div中使用时不起作用
运行Site_materials表,找到匹配项后将其存储在“NumberOFDeliveries”中, 这是应该显示在屏幕上的标签的IDAsp.net 标签赢得';在页脚模板/Panel/SecurePanel/Div中使用时不起作用,asp.net,label,Asp.net,Label,运行Site_materials表,找到匹配项后将其存储在“NumberOFDeliveries”中, 这是应该显示在屏幕上的标签的ID //DELIVERIES int NumberOfDeliveries = (from Deliveries in db.Site_Materials where Deliveries.Diary_Entry_Id == this.DiaryEntryId
//DELIVERIES
int NumberOfDeliveries = (from Deliveries in db.Site_Materials
where Deliveries.Diary_Entry_Id == this.DiaryEntryId
select Deliveries).ToList().Count();
if (NumberOfDeliveries > 0)
{
NoOfDeliveriesOnSite.Text = System.Convert.ToString(NumberOfDeliveries);
}
else
{
NoOfDeliveriesOnSite.Text = "0";
}
如果我在我的aspx页面中使用下面的标签,t将按预期显示。但我有一个问题,试图显示它在我想要的地方。。。内部页脚模板/Panel/SecurePanel/Div
<FooterTemplate>
<asp:Panel runat="server" ID="AllLinks" HorizontalAlign="Center" Width="600px" >
<mesh:SecurePanel runat="server" ID="EmployeeLink" CssClass="SmallBoxLink" WebMasters="true" Admins="true" Clients="true" Employees="true">
<div style="height:25px; margin-top:12px; margin-bottom:12px;">
<asp:Label ID="Delivery" runat="server" Text="Deliveries=" /><asp:Label ID="NoOfDeliveriesOnSite" runat="server" />
正如我所说,这段代码工作正常,并显示正确的数量(在aspx页面上的diff places使用时),但当我尝试在我想要的位置显示它时,我得到了错误:
来自政务司司长。声明“NoofDeliveResonsite”的页面不存在
任何关于为什么你必须在任何容器中找到控件的想法 您需要在问题中给出的代码示例上方添加此变量,以便对该变量的引用有效:
SecurePanel EmployeeLink = (SecurePanel)AllLinks.FindControl("EmployeeLink");
Label NoOfDeliveriesOnSite = (Label)EmployeeLink.FindControl("NoOfDeliveriesOnSite");
根据您的
FooterTemplate
的用途(GridView
,FormView
,等等),您可能还需要在其内部找到“AllLinks”面板
。如果它在页脚中,则需要将控件号设置为-1。在本例中,我在页脚中有一个标签,我想对其进行处理:
dim myLabel as label
myLable = myDataRepeater.Controls(myDataRepeater.Controls.Count - 1).FindControl("lableName")
如果您试图在用户控件中找到某个控件,则可能需要添加notehr.FindControl方法,即:
myLable = myDataRepeater.Controls(myDataRepeater.Controls.Count - 1).FindControl("lableName").findControls("anotherControl")