Stacky Stacky - 27 days ago 8
ASP.NET (C#) Question

How to make href link dynamic inside the gridview ?

I have been trying this but cannot get it done.

I have this link in item template.

<asp:TemplateField HeaderText="Tender's Details <br/> ٹینڈر کی تفصیلات">
<a href='<%#Eval("Url")%>/forms/general/print.aspx?OfficeID=<%# SharedUtility.EncryptURL(Eval("OfficeID").ToString()) %>&NITNo=<%# SharedUtility.EncryptURL(Eval("NITNo").ToString()) %>' class='<%#Eval("IsPublished").ToString()=="False"?"":"hidden"%>' target="_blank">

in href the link /print.aspx should be dynamic such as if OfficeID =1 then it should be /print.aspx else /print222.aspx.

That's all.

I tried modifying it but results in many other problems.

Answer Source

Why not use a ternary operator like you do with the class?

<%# Convert.ToInt32(Eval("OfficeID")) == 1 ? "print.aspx" : "print222.aspx" %>