我在.aspx的gridview中有这个代码,实际上31天中有31个这样的代码:
<asp:TemplateField HeaderText=" 28" SortExpression="Data28"
<ItemTemplate>
<a id="data28" href="javascript:openPopup('/subsidy/updatehour1.aspx?Data=<%# Eval("Data28") %>&TraineeID=<%#Eval("TraineeID")%>&RecordID=<%# Eval("RecordID")%>')">
<%# Eval("Data28")%>
</a>
</ItemTemplate>
</asp:TemplateField>
如果我添加runat="server"
,则运行该页面时会出错。
在后面的代码中,我需要使用以下代码来隐藏gridview中的特定href:
private void setMonthEndTextBox()
{
int lastDay = (int)ViewState["LastDay"];
foreach (GridViewRow row in this.GridView1.Rows)
{
for (int i = 29; i <= 31; i++)
{
((HtmlAnchor)row.Cells[i + 4].FindControl("Data" + i.ToString())).Visible = (i <= lastDay);
}
}
}
知道怎么做吗?感谢。
答案 0 :(得分:0)
HtmlAnchor是您代码中的错误方法
private void setMonthEndTextBox()
{
int lastDay = (int)ViewState["LastDay"];
foreach (GridViewRow row in this.GridView1.Rows)
{
for (int i = 29; i <= 31; i++)
{
((HtmlAnchor)row.Cells[i + 4].FindControl("Data" + i.ToString())).Visible = (i <= lastDay);
}
}
}