This is a migrated thread and some comments may be shown as answers.

Access an anchor tag in ItemTemplate

2 Answers 761 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Veteran
Mark asked on 26 Oct 2020, 04:54 PM

 <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 Answers, 1 is accepted

Sort by
0
Accepted
Doncho
Telerik team
answered on 28 Oct 2020, 03:58 PM

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/.

0
Mark
Top achievements
Rank 1
Veteran
answered on 28 Oct 2020, 06:28 PM
Wow thanks, just what I needed
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Veteran
Answers by
Doncho
Telerik team
Mark
Top achievements
Rank 1
Veteran
Share this question
or