Click here to Skip to main content
15,904,288 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have one combobox with flowers,fruits,vegetables
when i select combobox1 in combobox2 it has to display types of fruits(apple,mango,orange)..all this has to be done dynamically means getting the values from sql server
Posted
Comments
DamithSL 25-Jun-12 6:46am    
What have you tried so far? can you show the code and where are you stuck?
Sandeep Mewara 25-Jun-12 9:19am    
Where are you stuck?

you can solve this using a store proc which will provide all data according to group you choose from combo box and then on front end you can call that method on select index change event on windows or can set auto post back property to true if using web application.
 
Share this answer
 
Just add the event name to "onselectedindexchanged"property of Combobox as :
onselectedindexchanged="ddlEmpName_SelectedIndexChanged"

and add an event handler to code behind like this:

C#
protected void ddlEmpName_SelectedIndexChanged(object sender, EventArgs e)
      {
       
           // Your code here to fetch and assign data from database.

      }



Happy Coding :)
 
Share this answer
 
Comments
Member 9068558 25-Jun-12 6:57am    
I worked with this code it's not working...it's showing error at
MaskId = Convert.ToInt32(cmbmoduleid.Text);
----------------------------------------------------------------------
private void cmbmoduleid_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbmoduleid.SelectedIndex > -1 && cmbmoduleid.SelectedItem != null)
{

if (cmbmoduleid.SelectedText.ToString() != "")
{
MaskId = Convert.ToInt32(cmbmoduleid.Text);
DatasetForm = glbObj.srv.ViewDataSRV(clsGetViewXmlData.GetViewXMLData(gInfo.SchemaName, GlobalSP.FormInsert.Usp_FormInsert_SelectSubModule.ToString(), MaskId));
DataTable Dt = DatasetForm.Tables[0];

//cmbmoduleid.DataSource = new BindingSource(ImpecApplication.Cust.Reports.Global.GLB_FORMS, null);
cmbsubmoduleid.DataSource = Dt;
cmbsubmoduleid.DisplayMember = "SubModule_Name"; //colum you want to show in comboBox
cmbsubmoduleid.ValueMember = "SubModule_ID";
}
}

}
DamithSL 25-Jun-12 7:02am    
try MaskId = Convert.ToInt32(cmbmoduleid.SelectedText);
Simple In side the Combobox1 fire event you just call a fill method which will retrive data from db and bind in Combobox2.
In Combobox1 do AutoPostBack="True"
like Ex:-
C#
protected void Combobox1_SelectedIndexChanged(object sender, EventArgs e)

    {
        FillMethod(Combobox1.SelectedValue);
    }

public void FillMethod(int CategoryId)
{
//Fetch data from db where id=CategoryId
//Bind data into Combobox2
}
 
Share this answer
 
v2

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