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 .
My procedure accepts null values . only problem is how to pass tht from code behind th开发者_JAVA百科t the any text box value submitted it shud return the data.
Can any one help me on this .
Thanks Smartdev
Have you checked int.Parse
or int.TryParse
Methods along with 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
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!
精彩评论