How to fill dropdown list statically(Hardcoded)
I have 2 items
Text="Active" value="A"
Text="InActive" value="I"
and above values saved into database
Thanks,
How to fill dropdown list statically(Hardcoded)
I have 2 items
Text="Active" value="A"
Text="InActive" value="I"
and above values saved into database
Thanks,
If you want to do this all in a view, the code would look like this:
Also if you wanted to add a blank, it would look like this:
And if you wanted to have a particular item selected, it would look like this:
Notice I changed the
SelectList
line adding a"I"
parameter, this corresponds to the 'InActice' value causing it to be selected on page load.This code would generate this in HTML:
So if this is going to be static you can just use this. You can remove the
selected="selected"
if needed.I'm not exactly sure what you mean by "above values saved into database", do you have a model to go with these items? If you edit your question and add some examples of what your trying to do I can help you better.