如何空值转换成C#.NET字符串? [英] How to convert null value into string in c# .net?
问题描述
我使用的GridView控件的默认更新方法,它可以让我通过将细胞转化为文本框更新GridView控件本身一行。
I am using gridview's default update method in which it allows me to update row in gridview itself by converting cells into textboxes.
我要检查验证,如果一个特定的文本框(单元)保留为空或空白,则不能更新它的值。
I want to check validations that if a particular textbox (cell) remains empty or blank then it should not update its value.
有关我写了下面的code:
For that i have written following code:
string.IsNullOrEmpty(e.NewValues[0].ToString())
但它给像不设置到对象的实例对象引用错误。可它不能转换的空值 e.Newvalues [0]
为字符串
所有的答案都提前pciated AP $ P $。
All answers are appreciated in advance.
推荐答案
另一种方式:
String.IsNullOrEmpty(Convert.ToString(e.NewValues[0]));
的位(可能是不需要的)解释:
A bit of (probably unneeded) explanation:
Convert.ToString()
将返回null为(字符串)空
,和一个空的一个字符串(对象)空
(或任何其他NULL)。
Convert.ToString()
will return null for a (string)null
, and an empty string for an (object)null
(or any other null).
这两种情况将给出预期的结果,因为我们与 String.IsNullOrEmpty检查()
。
Either case will give the expected result, because we're checking with String.IsNullOrEmpty()
.
在任何情况下,它的行为是一样的 someValue.ToString()
,除了它处理的情况下,其中 someValue中
为null。
In any case, its behaviour is the same as someValue.ToString()
except it handles the cases where someValue
is null.
这篇关于如何空值转换成C#.NET字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!