Click here to Skip to main content
15,914,160 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai,

C#
DropDownList1.DataTextField ="textname";
DropDownList1.DataTextField ="textid";
DropDownList1.DataBind();


what are ways databind in DropDownList box.

thanks,
Karthikeyan
Posted
Updated 13-Dec-10 6:58am
v3

Thank you for your question. You can follow the bellow code.

C#
// Specify the data source and field names for the Text
// and Value properties of the items
// in the DropDownList control.
DropDownList1.DataSource = YourDataSourceHere();
DropDownList1.DataTextField = "textname";
DropDownList1.DataValueField = "textid";
// Bind the data to the control.
DropDownList1.DataBind();
// Set the default selected item, if desired.
DropDownList1.SelectedIndex = 0;


Thanks,
Mamun
 
Share this answer
 
Yes you are on correct way of databinding DropDownList.

Just correct your code by writing DataValueField for binding value rather then DataTextField twice.

It's just done.
 
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