Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1775
  • Last Modified:

Microsoft Visual C# Combo box list items

Hi experts, I have a combo box with data bound items, I have a Town table like this:

Town ID  = 7
Town description  = Demo Town

there are about 10 towns, and the combo box only displays the current selected record of my database...

How do i list all 10 towns inside of the combo box?
untitled12.bmp
0
Benvor
Asked:
Benvor
1 Solution
 
Pratima PharandeCommented:
Not sure I got your qestion or not .
can you explain bit n=more?

Normal Combo box binging code is like this


   string strConnectionString = "connetion string here"; 
    SqlConnection cnn = new SqlConnection(strConnectionString); 
    
    SqlClient.SqlCommand cmd = new SqlClient.SqlCommand("SELECT * FROM table ", cnn); 
    cmd.CommandType = CommandType.Text; 
    SqlClient.SqlDataAdapter dacmd = new SqlClient.SqlDataAdapter(cmd); 
    DataSet dscmd = new DataSet(); 
    dacmd.Fill(dscmd); 
   DropDownList1.DataSource = ddDR;
DropDownList1.DataTextField = "DisplayValueFieldFromDB";
DropDownList1.DataValueField = "DataValueFieldFromDB";
DropDownList1.DataBind();

Open in new window

0
 
BenvorAuthor Commented:
The combo box displays the correct info, but there is only 1 item in the list at a time, and i want to display the whole list of towns inside the combo box
0
 
angus_young_acdcCommented:
What code are you using to set the data the combio box should use?  It seems like you may be just returning 1 value from the database and using that to populate the combo box.
0
 
BenvorAuthor Commented:
I'm not using any code, that results I get from just selecting the "ComboBox tasks/Use data bound items" and selecting the appropriate binding source
0
 
drypzCommented:
Maybe the problem is in your sql query which only return a single record.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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