Populate DropDown list at run-time

J

John Beschler

I have a web page that is accessing its data via WebServices. I've created a
WebService that Returns the data I need for my DropDown control as a DataSet.
How can I populate the DropDown from the DS returned by the WebService at
page load?

Thanks,
John
 
B

Brock Allen

Assign the DataSource properety to a collection and set the DataTextField
and perhaps the DataValueField to the property names form the item it's databinding
to, then call DataBind().
 
J

John Beschler

Brock,

Thanks for the help; but, I'm still confused. Do I doo that in the
designer. or in the code? If I do it in the designer, there are no Datasets
associated with the project to bind the data to. If I do it in code, the
controls do not exist at page load time so there is nothing to bind the data
to.

Sorry for my ignorance, but I am just beginning the conversion to .NET.

Thanks,
John
 
J

John Beschler

I figured it out!

I created a dataset in the designer with the table structure to match my
dataset from the webservice.

Then, I bound thecontrol to that dataset in the designer.

Then, at page load time, I created a new dataset to store the dataset
returned from the webservice.

Next, I copied the dataset from the webservice into the dataset I created in
the designer.

Finally, I called DataBind to bind the dataset from the designer to the
dropdown.

Here's the pageload code:
localhost.Service1 svc = new localhost.Service1();
DataSet ds = new DataSet();
ds = svc.GetNames();
this.dataSet1 = ds.Copy();
this.DropDownList1.DataBind();
 

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

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top