• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

bind combo box

Hi Expert,
   I have two table. One Product ( id, type_id, name, price) and ProductType(Type_id, name, description). Now In from I want to neviogate the product . The Type_id will be in ComboBox).

Plaese tell me how to bind combo box.
  • 3
1 Solution
Bob LearnedCommented:
Windows Forms example:

this.comboBox1.DataSource = this.dataSet1.Tables("Product");
this.comboBox1.DisplayMember = "name";
this.comboBox1.ValueMember = "type_id";

For ASP.NET that would be slightly different.

Following is the way to bind your combobox(as u asked) with required field values in ASP.NET.
Hope this wil help u.

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<YOUR CONNECTIONSTRING>"
            SelectCommand="SELECT [type_id] FROM [Product]"></asp:SqlDataSource>

<asp:ListBox ID="ListBox1" runat="server" DataSourceID="SqlDataSource2" DataTextField="type_id" DataValueField="type_id"></asp:ListBox>
Can you please tell the problem is solved or not? because i think the answer given is correct.
Hi TheLearnedOne,
If the problem is not solved with given suggestions, there should be a comment from the author, with the reason that what is the output with given suggestion. I guess the solution given is the right one.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now