I am trying to dynamically create a template field which has an item template consisting of a hyperlink field. Trying to recreate the below code in the backend asp.net code:
<asp:TemplateField HeaderText="Total" SortExpression="TotalCases" ItemStyle-HorizontalAlign ="Center" ControlStyle-ForeColor="Black">
<ItemTemplate>
<asp:HyperLink ID="TotalCases" Target="_blank" runat="server" Text='<%# Eval("TotalCases") %>' />
</ItemTemplate>
</asp:TemplateField>
I have created a new template field called totalcases and now I am trying to get the item template as a hyperlink field which is where I am getting stuck
TemplateField TotalCases = new TemplateField();
TotalCases.HeaderText = "Total";
TotalCases.SortExpression = "TotalCases";
TotalCases.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
TotalCases.ControlStyle.ForeColor = System.Drawing.Color.Black;
TotalCases.ItemTemplate = new HyperLink(); //THIS DOESNT WORK
clientgv.Columns.Add(TotalCases);
Error: cannot convert type System.Web.UI.WebControls.Hyperlink to System.Web.UI.Template. An explicit conversion exists.
I am trying to get the hyperlink URL assigned in the rowdatabound method but it cant find the hyperlink and is coming back as null on debug
HyperLink hltc = (HyperLink)e.Row.FindControl("TotalCases");
class HyperlinkColumn : ITemplate{ public void InstantiateIn(System.Web.UI.Control container) { HyperLink hypLink = new yperLink(); container.Controls.Add(link); }}Try this link stackoverflow.com/questions/13288215/…