2016-12-15 53 views
0

我不知道如果我做錯了什麼,但我想做什麼,是顯示我們從數據庫中檢索到的註冊表數量,並將其顯示在我們的頁腳上,有「總申請人:(在這裏我們應該能夠看到項目的總數)」,但我甚至不能調用asp:label來加載它.aspx.cs。這裏是我的代碼(標籤應該是lblTotal)FooterTemplate無法在我的.aspx.cs中調用任何函數

<blockquote> 
     <asp:GridView ID="gvApplicants" runat="server" AllowPaging="True" AllowSorting="true" 
      AutoGenerateColumns="False" DataKeyNames="Id" CellPadding="5" ForeColor="#333333" 
      GridLines="None" PageSize="10" ShowFooter="True" Width="100%" Font-Size="9pt" 
      OnSorting="gvApplicants_Sorting" OnPageIndexChanging="gvApplicants_PageIndexChanging"> 

      <Columns> 
       <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" 
        SortExpression="Id" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Top" /> 
       <asp:TemplateField HeaderText="Complete Name" SortExpression="FirstName"> 
        <HeaderStyle HorizontalAlign="Left" /> 
        <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" /> 
        <ItemTemplate> 
         <a href='candidato.aspx?key=<%#Eval("Key")%>'> 
         <%# Eval("FirstName") %> 
         <%# Eval("MiddleName") %> 
         <%# Eval("LastName") %> 
         <%# Eval("SecondLastName") %></a> 
         <br /> 
         <small><%# GetLabels(Eval("Id").ToString())%></small> 
        </ItemTemplate> 
        <FooterTemplate> 
         Total candidates: <asp:Label ID="lblTotal" runat="server"></asp:Label> 
        </FooterTemplate> 
       </asp:TemplateField> 

       <asp:TemplateField HeaderText="Vacancies" SortExpression=""> 
        <HeaderStyle HorizontalAlign="Left" /> 
        <ItemStyle HorizontalAlign="Left" /> 
        <ItemTemplate> 
         <%# GetVacante(Eval("email").ToString())%> 
        </ItemTemplate> 
       </asp:TemplateField> 

       <asp:BoundField DataField="Status.Nombre" HeaderText="Status" 
        SortExpression="Status.Nombre" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Top" /> 
       <asp:TemplateField HeaderText="Created Date" SortExpression="CreatedDate"> 
       <HeaderStyle HorizontalAlign="Left" /> 
       <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" /> 
        <ItemTemplate> 
         <asp:Label ID="Label1" runat="server" Text='<%# Eval("createdDate", "{0:MMMM dd, yyyy. H:mm}") %>'></asp:Label> 
        </ItemTemplate> 
       </asp:TemplateField> 
       <asp:BoundField DataField="Rating" HeaderText="Rating" SortExpression="Rating" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Top" /> 
      </Columns> 

和.aspx.cs

private void LoadApplicants(Entity.Vacante v) 
{ 
    try 
    { 
     ASF.HC.JobApplication.BO.User u = new BO.User(); 
     gvApplicants.DataSource = u.GetAllByVacancy(v); 
     gvApplicants.DataBind(); 
     LoadData() 

    } 

    catch(Exception ex) 
    { 
     this.lblError.Text = "There was an unexpected error getting applicants: " + ex.Message; 
    } 
} 
    protected void LoadTotal() 
    { 
     foreach (GridViewRow row in gvApplicants.Rows) 
     { 
      if (row.RowType == DataControlRowType.Footer) 
      { 
       Label myLabel = row.FindControl("lblTotal") as Label; 
       if (myLabel != null) 
       { 
        myLabel.Text = "hola"; 
       } 
      } 
     } 
    } 
+0

「傢伙」......你知道有女性開發者嗎? – Fuzzybear

+0

我的意思是男性和女性一樣。夥計們和加爾斯對我來說似乎並不實際。 –

回答

1

你正在做的事情是錯誤的。您仍在使用webforms。 只是開玩笑,問題是,你不能像其他控件一樣使用id訪問模板文件中的控件。你需要做這樣的事情。

foreach(GridViewRow row in myGridView.Rows) { 
    if(row.RowType == DataControlRowType.Footer) { 
     Label myLabel= row.FindControl("myLabelId") as Label; 
     if(myLabel!=null) 
     { 
     //Do your stuff 
     } 
    } 
} 
+0

這不是我的編碼:(這是一個任務,回到編程主題,我甚至不能用這個顯示一個「Hello World」,我做錯了什麼?我甚至在Page_Load()。 –

+0

我在原文中添加了我想要模擬的內容 –

相關問題