开发者

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 catal开发者_运维技巧ogid 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


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜