如何从后面的代码中找到一个由javascript弹出的href控件?

时间:2022-08-25 23:02:51

I have this code in gridview in .aspx, and actually having 31 of these for 31 days:

我在。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>

If I add runat="server", then there is an error when I run the page.

如果我添加runat="server",那么当我运行页面时就会出现错误。

In the code behind, I need to use folowing code to hide specific href in the gridview:

在后面的代码中,我需要使用folowing代码在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);
            }
        }
    }

Any idea how to do it? thanks.

知道怎么做吗?谢谢。

1 个解决方案

#1


0  

HtmlAnchor is the wrong method in your code

在您的代码中,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);
            }
        }
    }

#1


0  

HtmlAnchor is the wrong method in your code

在您的代码中,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);
            }
        }
    }