It looks like you are using Server-side object model via C# at custom visual web part.
So Consider you have drop-down list called DropDownList1
at your custom visual web part , click on this control in design view to open code view with this event DropDownList1_SelectedIndexChanged
within this event you can get the selected value as the following :
string selecteditem = DropDownList1.SelectedItem.ToString();
Additionally, To fill the second dropdown list , at the same event DropDownList1_SelectedIndexChanged
try to add this code based on your entries as the following
using (SPSite site = new SPSite(http://siteurl))
{
using (SPWeb web = site.OpenWeb())
{
string selecteditem = DropDownList1.SelectedItem.ToString();
SPList myListe = web.Lists.["Categorie"];
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Title'/>" + "<Value Type='Text'>" + selecteditem + "</Value></Eq></Where>";
SPListItemCollection items = myListe.GetItems(query);
foreach (SPListItem item in items)
{
DropDownList2.Items.Add(item ["Title"].ToString())
}
}
}
Note :
I advise adding update panel
to hold the 2 drop down lists to avoid postback and page load every time you select an item from the first drop down list
At this code query.Query
build your where condition based on your requirement