question

JaakIvask-9402 avatar image
0 Votes"
JaakIvask-9402 asked YijingSun-MSFT answered

<asp:hyperlink with dynamic data

Hello,

In webapp I have <asp:GridView.. and inside it column:

  <asp:TemplateField HeaderText="PS" ItemStyle-HorizontalAlign="Center">
                     <ItemTemplate>
                         <%#(int)Eval("PaymentStatusId") == int)PaymentStatusEnum.Paid ? "P" :   
                          (int)Eval("PaymentStatusId") == (int)PaymentStatusEnum.PendingOK ? "PINV" : "H"%>    
    
                          //code I want to add
        
      </ItemTemplate>
          
 </asp:TemplateField>

I want to dynamically add URl to send remider and add it instead of the comment above:

 <a href="https://www.company.com/et/orders/<%#((Order)Container.DataItem).Parent.OrderGuid%>/reminder" target="_new">Saada meeldetuletus</a>

the URL formed correctly. Problem is that it is displayed in every row of the grid.

Insted of the simple HTML url I can use <asp:Hyperlinc to conditionally display the URL, but I can't get it to work with dynamic data:

 <asp:HyperLink id="hyperlink1"  
                   NavigateUrl="http://www.company.com/et/orders/" + <%#((Order)Container.DataItem).Parent.OrderGuid%> + "/reminder"
                   Text="Send reminder"
                   Target="_new"
        Visible="<%#(int)Eval("PaymentStatusId") == (int)PaymentStatusEnum.PendingOK ? "True" : "False"%>"
                   runat="server"
   />     

The error is: "The server tag is not well formed." The url has to redirect another domain. If I add <%#((Order)Container.DataItem).Parent.OrderGuid%> alone to NavigateUrl it's working.




dotnet-aspnet-core-generaldotnet-aspnet-webforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered

Hi @JaakIvask-9402,

The error is: "The server tag is not well formed."

The problem is IntelliSense, "<" will sense the nearest ">", so it will cause confusion.

Maybe you can try the following code:

 NavigateUrl='<%#String.Format("https://www.company.com/et/orders/{0}/reminder",((Order)Container.DataItem).Parent.OrderGuid)  %>'

You could not use double quotes within double quotes so use combination of single and double quotes.

 Visible='<%#(int)Eval("PaymentStatusId") == (int)PaymentStatusEnum.PendingOK ? true : false%>'

Your full codes need to be like this:

  <asp:TemplateField>
                         <ItemTemplate>
                             <asp:HyperLink ID="hyperlink1" runat="server" Text="Send reminder" Target="_new" NavigateUrl='<%#String.Format("https://www.company.com/et/orders/{0}/reminder",((Order)Container.DataItem).Parent.OrderGuid)  %>'  Visible='<%#(int)Eval("PaymentStatusId") == (int)PaymentStatusEnum.PendingOK ? true : false%>' ></asp:HyperLink>
                         </ItemTemplate>
                     </asp:TemplateField>

Best regards,
Yijing Sun



If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.