0

Using SQL Server and ASP.NET.

I am populating a drop down list on a form from one table sat NAME, ID... where dropdown text=NAME and dropdown value=ID...

Form is having field storing this ID field value. (act as foreign key referencing above table having NAME, ID fields)

and 1st item in dropdown list is : Text='Select'. What value should be specified for this item, so that if nothing is selected (i.e. text = select) then in database it should not store anything.

If I use empty string it takes zero as vlaue, if I use NULL then it stores NULL value.

4 Answers 4

2

the "SELECT" value in the prev drop down shoule be -1.

Sign up to request clarification or add additional context in comments.

Comments

1

I agree with Dilip..assuming that your ID is of integer type, you should consider using -1 as your 'null/nothing' value i.e set the 'Select' dropdownlist item's value to -1...just remember to do the same in your item, edit and insert templates.

Comments

1

You have to assign -1 (or) 0 to the "select" as value, you need to validate in

client-side to prevent the storing the those values into the database.

If the dropdown list is not mandatory - then validate on the server side or Stored proc,

if the coming value for insert or update is -1 or 0 then store it as NULL.

Comments

0

You cannot store nothing in database. Either it is empty string (if ID field is char type) or null (as it should not be as foreign key is involved). You need to check before posting to database what is selected from dropdown and send the correct value to database.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.