我不知道我做错了什么,但我想做的是显示我们从数据库中检索的注册表数量,并将其显示在我们的页脚上,我们有“申请人总数:(这里我们应该是能够查看项目总数)“但我甚至无法调用asp:标签将其加载到.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";
}
}
}
}
答案 0 :(得分:1)
你做错了什么。您仍在使用网络表单。 只是开玩笑,问题是你无法像其他控件那样使用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
}
}
}