CASE 函数是特殊的 Transact-SQL 表达式,它允许按列值显式可选值。数据中的更改是临时的,没有对数据进行永久更改。例如,CASE 函数可以在 state 列中有 CA 值的行的查询结果集内显示 California。
CASE 函数包含:
下面示例在查询结果集内显示每个作者所居住州的全名:
SELECT au_fname, au_lname, CASE state WHEN 'CA' THEN 'California'
WHEN 'KS' THEN 'Kansas'
WHEN 'TN' THEN 'Tennessee'
WHEN 'OR' THEN 'Oregon'
WHEN 'MI' THEN 'Michigan'
WHEN 'IN' THEN 'Indiana'
WHEN 'MD' THEN 'Maryland'
WHEN 'UT' THEN 'Utah'
END AS StateName FROM pubs.dbo.authors ORDER BY au_lname
(3)、绑定用Eval时,如何判断他是否为空
用Convert.IsDBNull
如下面代码:
SelectedValue='<%# Convert.IsDBNull(Eval("提现方式"))?"请选择提现方式":Eval("提现方式") %>'
(4)、可以使用自定义的方法(函数)在前台页面上处理上面提到的方法1和方法3的问题。
(5)、附一文章(地址:http://blog.sina.com.cn/s/blog_414cc36d01000933.html)
具体内容如下
Maybe this is obvious, but it wasn’t obvious to me. I’m binding
some data in a repeater that has the following output based on two
numeric columns in my database. It doesn’t matter why or what the
data represents. It’s just two pieces of data
with some formatting:
42, (123)
Basically these are two measurements. Initially, I would databind
this like so:
<%# Eval("First") %>, (<%# Eval("Second") %>)
The problem with this is that if the first field is null,
I’m left with this output.
, (123)
Ok, easy enough to fix using a format string:
<%# Eval("First", "{0}, ") %>(<%# Eval("Second") %>)
But now I’ve learned that if the first value is null,
the second one should be blank as well. Hmm...
I started to do it the ugly way:
<%# Eval("First", "{0}, ") %>
<%# Eval("First").GetType() == typeof(DBNull) ? "" : Eval("Second", "({0})")%>
*Sniff* *Sniff*. You smell that too? Yeah, stinky and hard to read. Then it occured to me to try this:
<%# Eval("First", "{0}, " + Eval("Second", "({0})")) %>
Now that code smells much much better!
I put the second Eval statement as part of the format string
for the first. Thus if the first value is null,
the whole string is left blank. It’s all or nothing baby!
Exactly what I needed.