Stacky Stacky - 5 months ago 40
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" %>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download