ASP.NET DropDownList Default Value As "NULL"

Locked ASP.NET DropDownList Default Value As "NULL"

  • Friday, March 05, 2010 9:29 AM
     
     
    Hi Experts,

    I have Patient details form. From that I am storing the data to DB using Stored Procedure.

    In table, all fields are allowed null except Primary key.

    When I store data, then I will stored using .Text property.

    For non-mandatory field, if text box value is "" then it will stored, but in case DropDownList if I pass empty string ("") to DB then it will show me error as

    "Input string was not in correct format"   

    Why?

    I have used DropDownList's SelectedItem.Text and SelectedValue . But in both case it show me the same error.

    Is there any case to pass default value of DropDown value as NULL?

    Or any other idea?

    Note : I am using LINQ. (.NET FW 3.5) and SQL Server 2008.

    Thanks.


    "Knowledge Shared Is Knowledge Gained"

All Replies

  • Friday, March 05, 2010 9:35 AM
     
     
    Pass a DbNull (namespace: System)
    Ganesh Ranganathan
    [Please mark the post as answer if it answers your question]
    blog.ganeshzone.net
    • Marked As Answer by Vijay Jadhav Friday, March 05, 2010 9:37 AM
    • Unmarked As Answer by Vijay Jadhav Friday, March 05, 2010 9:37 AM
    •  
  • Friday, March 05, 2010 9:38 AM
     
     
    Hi Ganesh,

    Thanks for the reply.

    Can't get you.

    Will you explain it in details?

    Thanks.


    "Knowledge Shared Is Knowledge Gained"
  • Friday, March 05, 2010 9:42 AM
     
     
    Ok Ganesh.

    I got it man!

    But I don't want to hard code it while storing to DB.

    If there is some value for DropDown then makes problem.

    Or while storing to SP, I need to check it whether it is NULL or not?

    Right?
    "Knowledge Shared Is Knowledge Gained"
  • Friday, March 05, 2010 9:55 AM
     
     
    Hi Ganesh,

    Tried it but not working while passing value as DbNull.

    I think this is due to mis-match of Data Type.

    Any solution ?
    "Knowledge Shared Is Knowledge Gained"
  • Friday, March 05, 2010 10:36 AM
     
     Answered
    Hi All,

    Got it.

    Please check the following URL :

    http://forums.asp.net/p/1532814/3715059.aspx#3715059

    Thanks.

    "Knowledge Shared Is Knowledge Gained"
    • Marked As Answer by Vijay Jadhav Friday, March 05, 2010 10:36 AM
    •