[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how can I bind the dataset to a dropdownlist, i want to use the field "product id" as  the value,  and "product name" as the  label

Posted on 2004-10-28
4
Medium Priority
?
2,001 Views
Last Modified: 2009-12-16
i have a function to return the value from a sql statement "select * from product"

how can I bind the dataset to a dropdownlist, i want to use the field "product id" as  the value,  and "product name" as the  label
0
Comment
Question by:musclejack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 18

Accepted Solution

by:
tusharashah earned 2000 total points
ID: 12436329
You can bind it like following:

DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "ProductName";
DropDownList1.DataValueField = "ProductID";
DropDownList1.DataBind();

-tushar
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12436514
and if you ever needed it for a datareader:
'where dr is your datareader
 dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
        Me.ddlAssignedTechnician.DataSource = dr
        Me.ddlAssignedTechnician.DataTextField = "LastName"
        Me.ddlAssignedTechnician.DataValueField = "TechnicianID"
        Me.ddlAssignedTechnician.DataBind()
0
 
LVL 8

Expert Comment

by:daffodils
ID: 12436680
tusharshah is right.. so is AerosSaga if you want to use a data reader..

Just remember to bind it within if(!IsPostBack).. block.. so that the data binding occurs only the first time the page loads, and not on every postback! If binding occurs on evey page load, you would lose the SelectedItem/SelectedIndex value.

if(!IsPostBack)
{
   DropDownList1.DataSource = ds;
   DropDownList1.DataTextField = "ProductName";
   DropDownList1.DataValueField = "ProductID";
   DropDownList1.DataBind();
}
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12436942
Aeros and Daffodils are right on this.  Populating a drop down is always a straight forward query of data and so you definitely should be using a data reader rather than a dataset.  Datasets are for when you need to get data into a grid where you'll be sorting, updating, etc. the data.

John
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question