使用中的值如果标记了条件 [英] using values within if conditions in mark up

查看:122
本文介绍了使用中的值如果标记了条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个从SQL if语句里面拉了一个值。理想的情况是我想要做的相当于

I want to use a value that is pulled from the SQL within the if statement. Ideally i want to do the equivalent of

<% If DataBinder.Eval(Container, "DataItem.BookID") == 1 Then%>

有没有办法用正确的语法来做到这一点?

Is there a way to do this with the correct syntax?

推荐答案

这是你怎么把条件aspx文件。只是我的理解一个粗略的示范基地:

This is how you put conditions in aspx file. Just a rough sample base on what I understand:

<%# System.Convert.ToInt32((DataBinder.Eval(Container.DataItem, "BookID")!="") ? DataBinder.Eval(Container.DataItem, "BookID"):0) %>

请确保您有INT的BookID没有任何其他类型。

Make sure you have int in BookID not any other type.

进一步的解释:

如果你想有一个if else条件:

In case you want to have an if else condition:

<%# If DataBinder.Eval(Container.DataItem, "DATAFIELD") <> "" Then

   Response.Write("something")

End If %> // This is invalid 

上面的语句可以正确写在aspx文件,因为这:

The above statement can be properly written in aspx file as this:

<%# DataBinder.Eval(Container.DataItem, "DataField").Equals("")?"":"Something"%>

这篇关于使用中的值如果标记了条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆