DropDownList and DataSet. Where is my error?

E

Emanuele

Hi People, I want populate one DropDownList with a DataSet.
I've got one problem when I pass the data and text value. My code
(propabily wrong)
pass always the first value of my droplist.

DataSet dst = new DataSet();


dst = myobject.GetDataSet();


droplist.DataSource = dst.Tables[0];
droplist.DataTextField =
dst.Tables[0].Columns["TextValueColumn"].ToString();
droplist.DataValueField =
dst.Tables[0].Columns["DataValueColumn"].ToString();
droplist.DataBind();

***************************
this.Label1.Text = droplist.SelectedItem.Text;
this.Label2.Text = droplist.SelectedItem.Value;

Can you help me?

(sorry for my english, but I'm italian....!)
 
E

Emanuele

Hi People, I want populate one DropDownList with a DataSet.
I've got one problem when I pass the data and text value. My code
(propabily wrong)
pass always the first value of my droplist.

DataSet dst = new DataSet();

dst = myobject.GetDataSet();

droplist.DataSource = dst.Tables[0];
droplist.DataTextField =
dst.Tables[0].Columns["TextValueColumn"].ToString();
droplist.DataValueField =
dst.Tables[0].Columns["DataValueColumn"].ToString();
droplist.DataBind();

***************************
this.Label1.Text = droplist.SelectedItem.Text;
this.Label2.Text = droplist.SelectedItem.Value;

Can you help me?

(sorry for my english, but I'm italian....!)

Nobody can help me?
 
D

David Wier

Don't worry - I wish I could speak Italian half as good as you speak English
are you having troubles setting the DataTextField/DataValueField, before
binding, or in the label part you had below it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top