Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to bind dropdownlost by 2 fields but want to show only 1 value at runtime in dropdownlist....forexample->i have 1 dropdownlist and binded it that by 2 fields i.e. id,name and at run time i want to show only name in ddlist not id....how it can possible tell me plz..............
Posted

in this way you can do this
in my table i have AREA_ID,AREA_NAME are columns

ddlArea my dropdownlist id
C#
ddlArea.DataSource = datatable;
ddlArea.DataTextField = "AREA_NAME";
ddlArea.DataValueField = "AREA_ID";
ddlArea.DataBind();
 
Share this answer
 
v3
Comments
pallavi ajin 8-Oct-11 2:49am    
but 1 more thing on that page its showing data.nw i want to insert that br_id,br_name into table along with others values.for the insertion of br_id i m using ddl.SelectedValue()and wht will i use for name ???may i use selectedItem()?and will i have to convert ddl.selectedvalue into integer????
hitech_s 8-Oct-11 2:57am    
you can use this for getting name
ddlArea.SelectedItem.Text
Use this

C#
dropdown1.DataSource = ds;//ds is the dataset containing your source
         dropdown1.DataTextField = "namecolumn";
         dropdown1.DataValueField = "idcolumn";
         dropdown1.DataBind();
 
Share this answer
 
Comments
pallavi ajin 8-Oct-11 2:49am    
but 1 more thing on that page its showing data.nw i want to insert that br_id,br_name into table along with others values.for the insertion of br_id i m using ddl.SelectedValue()and wht will i use for name ???may i use selectedItem()?and will i have to convert ddl.selectedvalue into integer????
P.Salini 8-Oct-11 2:58am    
use ddl.SelectedItem.Text
please paste some code for better reply..

for this time.. try this

DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "ID";
DropDownList1.DataSource = ;//bind here ur datasource
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("Select", "0"));



hope this help u
 
Share this answer
 
v3
Comments
pallavi ajin 8-Oct-11 2:48am    
but 1 more thing on that page its showing data.nw i want to insert that br_id,br_name into table along with others values.for the insertion of br_id i m using ddl.SelectedValue()and wht will i use for name ???may i use selectedItem()?and will i have to convert ddl.selectedvalue into integer????
Vikas_Shukla_89 8-Oct-11 2:54am    
it depends on datatype of variable u r using
1) for Name, string name = ddl.SelectedItem.Text;
2) for Value, int value = Convert.ToInt32(ddl.SelectedValue);
Take a look at the following tutorial :

http://www.4guysfromrolla.com/webtech/071101-1.shtml[^]
 
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