Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

asp.net

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

what I am trying to do is:

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

I'm trying to link back to the item from a page.. and I have accomplished this for every item except the ones in catalogid 856 ...the url looks like: storefront.aspx?CatalogID=856&ProductID=AVE05418 that example is of one from catalog 856, problem is, is the productid being passed in the url is actually the a variable called CustItem so Im trying to pass the CustItem in the place of ProductID when the catalog is 856

Thank you

like image 418
Joe W Avatar asked Dec 27 '22 15:12

Joe W


2 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")))%>'
like image 160
James Johnson Avatar answered Jan 30 '23 12:01

James Johnson


You could use a ternary operator.

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

Way better than that would be fixing the bad data that's found its way into your database so you could avoid this ugliness in the first place.

like image 36
48klocs Avatar answered Jan 30 '23 12:01

48klocs