Html Anchor Tag RRS feed

  • Question

  • User-797751191 posted


      I am trying to access Html Anchor tag in gridview row. It is giving error The type or namespace name HtmlAnchor not found.

    if (e.Row.RowType == DataControlRowType.DataRow)

    HtmlAnchor lnkVoucher = e.Row.FindControl("lnkReject") as HtmlAnchor;



    Monday, July 1, 2019 5:45 AM


All replies

  • User288213138 posted

    Hi jsshivalik,

    I'm trying to reproduce your problem, but it works fine with me.

    The code:

    <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
                                <a id="lnkReject" runat="server">Anchor</a>                          
    protected void Page_Load(object sender, EventArgs e)
                if (!this.IsPostBack)
                    DataTable dt = new DataTable();
                    dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country") });
                    dt.Rows.Add(1, "John Hammond", "United States");
                    dt.Rows.Add(2, "Mudassar Khan", "India");
                    dt.Rows.Add(3, "Suzanne Mathews", "France");
                    dt.Rows.Add(4, "Robert Schidner", "Russia");
                    GridView1.DataSource = dt;
            protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
                if (e.Row.RowType == DataControlRowType.DataRow)
                    HtmlAnchor lnkVoucher = e.Row.FindControl("lnkReject") as HtmlAnchor;

    The result:

    You can also refer to this link:https://stackoverflow.com/a/3304899, It may be the .Net framework version problem.

    You can try recompiled your .net framework version.

    If you still have questions, please post your aspx code.

    Best regards,


    Monday, July 1, 2019 10:24 AM
  • User753101303 posted


    VS should suggest a fix such as using

    System.Web.UI.HtmlControls.SHtmlAnchor lnkVoucher= etc... or adding
    using System.Web.UI.HtmlControls;

    See https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/namespaces/ for details.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 1, 2019 11:09 AM