Can I pass an if statement in the following code? If not, is there an alternative?

<%#String.Format("~/storefront.aspx?CatalogID={0}&ProductID={1}", Eval("CatalogID"), Eval("ProductID"))%> 

I am trying to do the following:

  NavigateUrl='<%#String.Format("~/storefront.aspx?CatalogID={0}&ProductID={1}",Eval("CatalogID"), (Eval("CatalogID")=="856" ? Eval("ProductID") : Eval("CustItem")))%> 

I am trying to link the item back to the page .. and I did this for every item except the ones listed in the 4006 directory ... url looks like this: storefront.aspx? CatalogID = 856 & ProductID = AVE05418 this example refers to one of the catalog 856, the problem is that the productid is passed in the url is actually the CustItem variable, so I'm trying to pass CustItem instead of ProductID when the catalog contains 856

thanks

+4
source share
3 answers

You can try something like this:

 Eval("CatalogID") == 856 ? Eval("CustItem") : Eval("ProductID") 

EDIT

 NavigateUrl='<%#String.Format("~/storefront.aspx?CatalogID={0}&ProductID={1}",Eval("CatalogID"), (Eval("CatalogID").ToString() == "856" ? Eval("CustItem") : Eval("ProductID")))%>' 
+6
source

You can use the ternary operator .

 Eval((CatalogID==856) ? "CustItem" : "ProductID") 

Better than that would be fixing the bad data that got into your database so that you can avoid this ugliness in the first place.

+3
source

can anyone suggest how to deal with this situation?

I would fix it at the database level. The data is simply incorrect.

If you need to hack it, do not change anything that is visible outside the server (for example, the web service interface or the URL). Otherwise, someone may take advantage of your work to undermine your data.

Allow Eval in your URL just to ask for problems.

+1
source

Source: https://habr.com/ru/post/1369550/


All Articles