Click here to Skip to main content
15,908,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi good evening..
in my project while saving dropdown selected value its adding id of that selected value..i bind to dropdwon from other table..and while retrieving tat value am getting code.

how can i get name of that dropdown..i mean selected dropdown value not as id value?am using dynamic in my project.

i tried but am getting id of that value.
from tblGroup table am binding data to Dropdown in tblGroup contains..grpID,grpName
and i created one webform..from NewWebForm while saving data its saving to tblDocumentMaster tables column dmProjectCode (as tblGroup tables column grpID value)
so while retrieving i want grpName as dmProjectCode.but am displaying grpID..

see below code and suggest me..


ASM
DocumentMasterBLL objDMBusiness = new DocumentMasterBLL();
               DataSet ds = new DataSet();
               ds = objDMBusiness.GetLastEnteredDocumentDetails(DID, DocType);


string ProjectBid = ds.Tables[0].Rows[0]["dmProjectCode"].ToString();

SessionManager.CurrentProject = ProjectBid;




please help me to solve this..

thank you..
Posted
Updated 29-Aug-12 0:53am
v3
Comments
__TR__ 29-Aug-12 6:47am    
"how can i get name of that dropdown" - I am assuming you want to get the value displayed in dropdownlist.

try:
yourDropDownList.SelectedItem.Text
ythisbug 29-Aug-12 6:54am    
am using dynamic in my project.thanks

Hi try this:-
C#
string Name = DropDownList1.SelectedItem.Text;
//DropDownList1 is your DropDownList Control's ID.


All the Best.
--Rajesh.
 
Share this answer
 
Use
C#
dropdownList1.Text
to get the selected value in the dropdown
 
Share this answer
 
While binding the dropdown list you should take care of this. There is two properties which we need to set generally while binding the dropdownlist.
1. DataTextField
2. DataValueField
Set DataValueField value as your ID and DataValueField as your Name.

Then try calling this:
C#
string name = DropDownList1.SelectedItem.Text;

Now this time you'll get your required output. Avoid these kind of miner mistakes.


All the best.
--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900