views:

23

answers:

2

Hey,

I have a DropDownList called (DDL) in ASP.net page, I want that DDL contains some records of a table in the data base.

So I did this :

DDL.DataSource = myDataReader

DDL.DataBind()

But it's giving me (5 records) "the number of records of the table" but like this :

System.Data.Common.DataRecordInternel
System.Data.Common.DataRecordInternel
System.Data.Common.DataRecordInternel
System.Data.Common.DataRecordInternel
System.Data.Common.DataRecordInternel
A: 

you have to set the text and the key fields of the ddl before you databind

DDL.DataTextField = "textColumn";
DDL.DataValueField = "textColumn":
derek
@DEREK : How can i do it
dotNET
see my edits please
derek
+4  A: 

You should set DataTextField and DataValueField, otherwise data binding will perform .ToString() on every row and put it as item:

DDL.DataSource = myDataReader;
DDL.DataTextField = "[Text column name]";
DDL.DataValueField = "[Value column name]";
DDL.DataBind();
tpeczek
Thank you very much.
dotNET