[英]How pass null from code behind with textboxes
I have two textboxes and a drop down.User has a option that he should select drop down and enter value in any one of the texbox . 我有两个文本框和一个下拉菜单。用户可以选择一个下拉菜单,然后在任一texbox中输入值。
My procedure accepts null values . 我的过程接受空值。 only problem is how to pass tht from code behind tht the any text box value submitted it shud return the data. 唯一的问题是如何从代码中传递的任何文本框值后面的代码传递给数据。
Can any one help me on this . 谁可以帮我这个事 。
Thanks Smartdev 谢谢Smartdev
Have you checked int.Parse
or int.TryParse
Methods along with nullbale
int 您是否检查过int.Parse
或int.TryParse
方法以及nullbale
int
some thing similar would work 一些类似的东西会起作用
int? couldBeNullInt;
couldBeNullInt = int.Parse(someTextBox.Text);
if the value returned is null, pass null to your procedure otherwise pass the non null value 如果返回的值为null,则将null传递给您的过程,否则传递非null值
such as 如
if(couldBeNullInt.HasValue && couldBeNullInt.Value !=null)
You would want to do something like this: 您可能想要执行以下操作:
int? enteredValue = null;
if(!string.IsNullOrEmpty(textNumberEntry.Text))
{
int temp = 0;
if(int.TryParse(textNumberEntry.Text, out temp))
enteredValue = temp;
}
// Call proc with enteredValue, check enteredValue.HasValue first though!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.