0
   <mesh:SecurePanel runat="server" ID="retentionInvoiceDue" WebMasters="true" Admins="true" style="text-align:left; font-size:small;">
            <a class="alert" ID="a1">Alerts</a>
            <br>
            <asp:Panel ID="panelToPromptRetentionInvoiceDue" runat="server" 
                CssClass="retentionLinksOnHomePage" Visible="true">
                <asp:DataGrid ID="datagridToPromptRetentionInvoiceDue" runat="server" 
                    AutoGenerateColumns="false" GridLines="None" ShowHeader="false">
                    <Columns>
                        <asp:TemplateColumn>
                            <ItemTemplate>
                                <span>Site
                                    <asp:LinkButton ID="promptRententionInvoiceLink" CommandArgument='<%# Bind ("id") %>' OnCommand="getSessionVariableForWorkSiteID" runat="server">
                                        <asp:Label id="labelBindfromHomeToInvoice" runat="server" Text="<%# Bind('Site_Name') %>"/>
                                    </asp:LinkButton>retention due for invoicing 
                                </span>
                            </ItemTemplate>
                        </asp:TemplateColumn>
                    </Columns>
                </asp:DataGrid>
             </asp:Panel>
    </mesh:SecurePanel>

在cs文件中我有页面加载:

  Context db = new Context();

        var allWorkSites =
            (from worksites in db.Work_Sites
             select worksites).Distinct().ToList();

        List<Object> chosenInvoicesForRetention = new List<Object>();

        foreach (Work_Site worksite in allWorkSites)
        {
            if (!worksite.Invoicing_Complete)
            {
                Invoice lastInvoice = worksite.Invoices.OrderBy(w => w.id).LastOrDefault();

                if (lastInvoice != null)
                {
                    if (lastInvoice.Invoice_Date < DateTime.Now.AddMonths(0 - worksite.Number_of_Months))
                    {
                        chosenInvoicesForRetention.Add(worksite);
                    }
                }

            }
        }

        if (chosenInvoicesForRetention.Count == 0)
        {
            panelToPromptRetentionInvoiceDue.Visible = false;
        }

        else
        {
            datagridToPromptRetentionInvoiceDue.DataSource = chosenInvoicesForRetention;
            datagridToPromptRetentionInvoiceDue.DataBind();
        }

    }

为什么我收到错误:panelToPromptRetentionInvoiceDue & datagridToPromptRetentionInvoiceDue 不存在?


编辑:我应该提到,这段代码在我的项目的不同页面上工作正常,我只是将它复制过来,因为我想再次使用它,但也更改它正在链接的表......为什么它会从一个页面工作而不是另一个?

还删除了安全面板,但仍然无法正常工作

有人有想法么?将不胜感激

4

1 回答 1

1

我假设您需要使用FindControl来引用SecurePanel.

尝试将以下内容放在代码隐藏中引用它们的位置之上。

var datagridToPromptRetentionInvoiceDue = 
    (DataGrid)retentionInvoiceDue.FindControl("datagridToPromptRetentionInvoiceDue");

var panelToPromptRetentionInvoiceDue =
    (Panel)retentionInvoiceDue.FindControl("panelToPromptRetentionInvoiceDue");
于 2013-03-03T16:07:46.707 回答