Click here to Skip to main content
15,904,287 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am using n tier architecture, in that I need to populate the combo box named category. The database table name is ItemCategory and the fields are categoryID and CategoryName. When I click on the drop down box in my design I need to show all the data inside CategoryName.
Please help me.
Posted
Comments
syed shanu 14-Apr-14 2:28am    
So what is the problem .and what is here drop down box and combo box
My Doubt 14-Apr-14 2:33am    
I have a drop down list I need to populate db values to that.

1 solution

Hope so you are using combox it' means this is windows application.
See there is no confusion for databinding in a combobox. When you want see data in combobox which is exists in databse.You need to bind data in page load event. for this you need to get list of data in a DataSet or DataTable or in List of object. Just collect the data from your layer(It may be a business layer) and bind to datasource of combobox
Ex.
private void Page_Load(Object sender,EventArgs e)
{
List<itemcategory> listCategory=objBusinessLayer.GetItemCategories();
cmbItemCategory.DataSource=ListCategory;
cmbItemCategory.DataTextField="CategoryName";
cmbItemCategory.DataValueField="categoryID";
}
</itemcategory>


A Tool to create N-Layer Architecture Classes[^]
N-Tier: Begginer's guide in designing their application[^]
 
Share this answer
 
v2
Comments
My Doubt 14-Apr-14 2:39am    
private void BindCategoryName()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["name"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Select CategoryID,CategoryNamefrom ItemCategory", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
ddlCategory.DataSource = dt;
ddlCategory.DataTextField = "Category Name";
ddlCategory.DataBind();
ddlCategory.Items.Insert(0, new ListItem(String.Empty, String.Empty));
ddlCategory.SelectedIndex = 0;
}

in page load I call BindCategoryName();
My Doubt 14-Apr-14 2:40am    
But my code is direct it doesnot uses any layer structure. I need to populate values using layers data layer, business layer and presentation layer.
Please Help me
[no name] 14-Apr-14 2:50am    
So you need to study how to make layer structure, right!
See some links which is edited my links

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900