Access an anchor tag in ItemTemplate

3 posts, 1 answers
  1. Mark
    Mark avatar
    7 posts
    Member since:
    Oct 2018

    Posted 26 Oct Link to this post

     <telerik:GridTemplateColumn HeaderText="Total" DataField="Total" ColumnGroupName="inv" Aggregate="Sum" FooterAggregateFormatString="{0}" ItemStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center" FooterStyle-Font-Bold="true" FooterStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="60">

     <ItemTemplate>                                    
          <a href='../ubEntryQueue.aspx?team=<%# Server.UrlEncode(DataBinder.Eval(Container.DataItem,"TeamID").ToString()) %>&status=0&user=           <%=ddlViewUser.SelectedValue %>&group=<%=hfDepartments.Value %>' target="_blank"><%#DataBinder.Eval(Container.DataItem,"Total") %></a>
    </ItemTemplate>

    </telerik:GridTemplateColumn>

    for 1 cell I need to disable the anchor but unable to figure out how.  I am trying to do this server side.

    Thanks for any help in advance

  2. Answer
    Doncho
    Admin
    Doncho avatar
    75 posts

    Posted 28 Oct Link to this post

    Hi Mark,

    You can follow the suggestions in the Accessing Controls in RadGrid to get a reference to each control in the RadGrid cells.

    To be able to distinguish the desired Template column on the server I would recommend you set a UniqueName for the column. Additionally, in order to reach the anchor as an object on the server-side you need to set its runat attribute to "server", and also set it an id:

    <telerik:GridTemplateColumn HeaderText="Total" UniqueName="Total">
        <ItemTemplate>
            <a runat="server" id="templateAnchor" href='.....</a>
        </ItemTemplate>
    </telerik:GridTemplateColumn

    Then you can reach the anchor on the server, for instance in the ItemDataBound event of the RadGrid, and disable it in the desired way -  Disable a HTML <a> link/anchor tag:

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            var item = e.Item as GridDataItem;
            var cell = item["Total"];
            var anchor = cell.FindControl("templateAnchor") as System.Web.UI.HtmlControls.HtmlAnchor;
            anchor.Style.Add("pointer-events","none");
        }
    }
    Please let me know if any further questions come up!

    Kind regards,
    Doncho
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  3. Mark
    Mark avatar
    7 posts
    Member since:
    Oct 2018

    Posted 28 Oct in reply to Doncho Link to this post

    Wow thanks, just what I needed
Back to Top