Hi friends
I want to know, how to show default value in dropdownlist in HTML ? Example-suppose there are a dropdownlist for male/female, I want to show default value i.e. --sex-- in dropdownlist ? Please tell me anyone ?
Thanks
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Lajapathy ArunRank #354 · 7K reputationPosted May 4, 2012, 12:30 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted May 3, 2012, 11:48 PM EDT
u can do same thing just adding one record in data source of drop down list.
example if u use data table to bind drop down then add one row to that table.
DataRow datarow = dt.NewRow();
datarow["valueFiled"] = 0;
datarow["TextFiled"] = "--sex--";
dt.Rows.InsertAt(datarow, 0);
drpEmpId.DataSource = dt;
drpEmpId.DataTextField = "valueFiled";
drpEmpId.DataValueField = "TextFiled";
drpEmpId.DataBind();
hope this help.
SenthilkumarRank #387 · 6.5K reputationPosted May 4, 2012, 12:28 AM EDT
In HTML, you have the control called option.
Where you can have the set of options with default selected value.
Try this..
For other properties about option, go here.
Vineet Kumar SainiRank #257 · 9.8K reputationPosted May 4, 2012, 1:36 AM EDT