5
Answers

dropdownlist question

Photo of umair mohsin

umair mohsin

8y
897
1
ddl gender value is coming from database at page load event i want the gender to be selected at page load how can i do that fields are simple name,gender, city,dept,etc.....

Answers (5)

1
Photo of Dharmraj Thakur
244 7.7k 718.8k 8y
You have not mentioned that what you are using... asp.net web forms or MVC...
 
in both case these solution will help you...
 
Asp.net webforms:
https://www.aspsnippets.com/Articles/Populate-one-DropDownList-based-on-another-DropDownList-selected-value-in-ASPNet.aspx 
 
MVC:
http://stackoverflow.com/questions/27901175/how-to-get-dropdownlist-selectedvalue-in-controller-in-mvc
1
Photo of Rajeesh Menoth
66 27.1k 2.7m 8y
Hi,
 
The question is not clear buddy. What I understand you need to dispaly all or particular user information on page load. 
 
Example 1 :
  1. protected void DropDownList1_DataBound(object sender, EventArgs e)  
  2. {  
  3.     DropDownList1.SelectedValue // store it in some variable  
  4. }  
Reference :
 
http://stackoverflow.com/questions/5961488/how-can-i-get-the-selected-item-of-a-dropdownlist-the-first-time-my-page-loads
 
https://www.aspsnippets.com/Articles/DataBinding-DropDownList-Label-and-Textbox-Controls-in-ASP.Net.aspx 
 
0
Photo of Rafnas T P
141 13.4k 4.5m 8y
hi umair,
if you wanted to select gender coming from database as Male, female, these are your items in your dropdown then you can bind as follows
 
ddlgender.SelectedItem=gendercomingfromdbr;
 
if gender coming from database are in your dropdown values then
 
 ddlgender.SelectedValue=gendercomingfromdbr;
 
0
Photo of umair mohsin
969 405 74.6k 8y
my question is so precise and clear if for example on user login gender is male then on profile page ddl gender should be male value selected and in the case of female ,ddl gender should be female selected
0
Photo of Nilesh Jadav
81 23.1k 15.5m 8y
hey there !

The question is not clear here, you have to a littlebit more precise what you are asking for ? May be you are asking for cascading dropdownlist - here is the source you can check that :

http://www.c-sharpcorner.com/UploadFile/009464/cascading-one-dropdownlist-with-other-dropdownlist-in-asp-ne/

Hope that helps!