簡體   English   中英

FooterTemplate無法調用我的.aspx.cs中的任何函數

[英]FooterTemplate cant call any function in my .aspx.cs

我不知道我做錯了什么,但是我想做的是顯示我們從數據庫中檢索到的注冊數量,並在頁腳中顯示“總申請人數:(在這里我們應該能夠看到的項目總數)”,但我什至無法調用asp:label將其加載到.aspx.cs中。 這是我的代碼:(標簽應為lblTotal)

<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";
                }
            }
        }
    }

您做錯了。 您仍在使用網絡表單。 只是在開玩笑,問題在於您無法像其他控件一樣從具有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
        }   
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM