Joe W
Joe W

Reputation: 1567

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"))%>

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

Upvotes: 4

Views: 142

Answers (3)

James Johnson
James Johnson

Reputation: 46047

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")))%>'

Upvotes: 6

48klocs
48klocs

Reputation: 6103

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.

Upvotes: 3

Merlyn Morgan-Graham
Merlyn Morgan-Graham

Reputation: 59111

can anyone suggest how to deal with the given situation?

I'd fix it at the database layer. The data is just plain wrong.

If you have to hack around it, do not change the anything that is visible outside the server (e.g. a web service interface or URL). Otherwise someone could take advantage of your work-around to subvert your data.

Allowing an Eval in your URL is just begging for problems.

Upvotes: 1

Related Questions