如何将空值传递给asp.net中的标签 [英] how to pass null value to label in asp.net
本文介绍了如何将空值传递给asp.net中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将空值传递给asp.net中的标签?
how to pass null value to label in asp.net??
label.Text =null;
label.Text="";
label.Text=DBNULL;
不起作用??????
not working?????
推荐答案
label.Text = string.Empty;
如果要让标签显示空",则只需分配string.Empty.
If you want a label to display ''empty'', just assign string.Empty.
在这种情况下,您需要为DataTime字段传递DbNull.Value
.
请参考如何传递空值到asp.net中的datetime数据类型? [
You need to passDbNull.Value
for DataTime field in this case.
Please refer How to pass the null value to datetime datatype in asp.net?[^] for the same type of issue.
Thanks...
如果设置为空,标签文本将始终为空白(")而不为null.因此,您可以使用以下代码:-
if you set null label text will always be blank ("") and not null. hence, you can use the following:-
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = string.Empty ; // OR Label1.Text = null ;
Label2.Text = (String.IsNullOrEmpty(Label1.Text) ? "null" : "not null");
}
这篇关于如何将空值传递给asp.net中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文