Greg
Greg

Reputation: 648

what is the best pratice to save radio button list choice in database? ASP.NET

I was wondering what would be the best way to store the choice made of a radio button list in the database.

Should we store the index, item or the value? Storing the index for example would make it easy to populate the radio button list later from the database but it makes it hard to read the database entry directly if needed. Should we store maybe both index and value?

Thanks ahead.

Upvotes: 0

Views: 672

Answers (2)

Arkadiusz Kałkus
Arkadiusz Kałkus

Reputation: 18371

Good idea is to prepare following structure of tables:

  • Dictionaries
  • Values

Dictionaries represent list of possible radio button or drop down list types and values store list of items of a particular RBL/DDL type.

Tables should look like:

Dictionaries
------------
dictionaryID PK
description

and

Values
------
valueID PK
dictionaryID FK
value

Then you can reference from your model/view model entity to valueID.

SomeEntity
----------
someEntityID PK
someRadioChoice FK(valueID)

And of course if you want to populate a radio button or drop down list you can simply query values with some dictionaryID in where clause.

Upvotes: 1

Lorin
Lorin

Reputation: 86

Use a lookup table for storing your listitem specified information like text and use the value of the list item as (part) of primary key. Then just store the value as Tim Schmelter says.like this

Upvotes: 1

Related Questions