locked
Html Anchor Tag RRS feed

  • Question

  • User-797751191 posted

    Hi

      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;

    }

    Thanks

    Monday, July 1, 2019 5:45 AM

Answers

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">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>           
                                <a id="lnkReject" runat="server">Anchor</a>                          
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
    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;
                    GridView1.DataBind();
                }
            }
    
            protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    HtmlAnchor lnkVoucher = e.Row.FindControl("lnkReject") as HtmlAnchor;
                    Response.Write(lnkVoucher.ToString());
                }
            }
    

    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,

    Sam

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

    Hi,

    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