Drop Down List Doesn't Populate

herodotus299

Newcomer
Joined
Jul 21, 2006
Messages
1
I have a weird problem. I'm trying to populate a drop down list (ddlField01). When I debug, I can see the data in my Dataset, but after the auto postback, I don't see the value displayed. Here is what I'm using.

ddlField01.Text = dsMyDataset.Tables[0].Rows[0].ItemArray[1].ToString();

If I change it to a text box, it works fine.

txtlField01.Text = dsMyDataset.Tables[0].Rows[0].ItemArray[1].ToString();

The syntax I use for the drop down list is used in a few other drop downs without problem. Any ideas?

Thanks,
Jeremy
 
To populate a dataset you must use the following:
Code:
ddlField01.datasource = dsMyDataset.Tables[0];
ddlField01.databind();

In the event that you have more that one column in your datatable, you need to specify what column you want to display and optionally what column you want to use as a reference column.
Code:
ddlField01.DataTextField = "<ColumnName>"
ddlField01.DataValueField = "<ColumnName>"

Mike55.

herodotus299 said:
I have a weird problem. I'm trying to populate a drop down list (ddlField01). When I debug, I can see the data in my Dataset, but after the auto postback, I don't see the value displayed. Here is what I'm using.

ddlField01.Text = dsMyDataset.Tables[0].Rows[0].ItemArray[1].ToString();

If I change it to a text box, it works fine.

txtlField01.Text = dsMyDataset.Tables[0].Rows[0].ItemArray[1].ToString();

The syntax I use for the drop down list is used in a few other drop downs without problem. Any ideas?

Thanks,
Jeremy
 
Back
Top