2013-03-03 79 views
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文件我已經在頁面加載:不能綁定到datagrid?

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不存在?


編輯: 我應該指出,這個代碼工作正常,從我的prject不同的頁面,我只是複製過來,我想再次使用它,但改變它被鏈接過多表..爲什麼它會從一頁而不是另一頁工作?

也去掉了安全面板,但仍然不工作

人有什麼想法?將不勝感激

+0

什麼是''如果用戶控制,那麼你有正確的註冊它在頁面上。 – Sachin 2013-03-03 16:06:39

+0

是它的用戶控制 – John 2013-03-03 16:08:04

回答

1

我假設你需要使用FindControl引用SecurePanel內的任何控件。

嘗試將以下代碼置於代碼隱藏中引用的位置上方。

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

var panelToPromptRetentionInvoiceDue = 
    (Panel)retentionInvoiceDue.FindControl("panelToPromptRetentionInvoiceDue"); 
+0

謝謝你...似乎找到面板和數據網格,但現在它說'retentionInvoiceDue'在(DataGrid)retentionInvoiceDue.FindControl(「datagridToPromptReten .....」在當前上下文中不存在 – John 2013-03-03 16:13:15

+0

然後你肯定在看你的控件是如何註冊的問題。無論什麼'mesh:SecurePanel'都是...... – Khan 2013-03-03 17:13:56