Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Think the question pretty much sums it up.

My requirement is simple,
1)Have populated a dropdown from database.
2) Based on the selected value in dropdown, I have to show a table.
ie make the table visible for some drop down selections alone.

Now, it looks pretty simple, but Iam breaking my head for the past 2 hours on this.

What I have done is, I have tried checking the dropdown.selectedvalue.text="something" inside the dropdown selected index changed, but it doesnt work.

I know Iam missing something basic here.

Pls guide me in the right path.

Thanks.
Posted

Try DropDownList.SelectedIndex Property [^] - should be a guide to get stared with selected change.
 
Share this answer
 
The below code needs to be written in the selectedindexchanged event of the dropdown.
C#
ComboBox cmb = (ComboBox)sender;
if (cmb.SelectedValue.ToString().Equals("Something")
{
    //Do Something
}


Hope this helps.
 
Share this answer
 
Comments
Mukesh Madhav 1-Sep-14 1:45am    
Thanks Ajay for the reply.

Sorry for being stupid.
But I cant usee ComboBox class, do I need to change the dropdownlist control to a combobox control to accomplish this ?
ChauhanAjay 1-Sep-14 1:57am    
No you dont need to change sorry for the misunderstanding.
DropDownList cmb = (DropDownList)sender;
if (cmb.SelectedValue.ToString().Equals("Something")
{
//Do Something
}

The above change should do.
Based on the fact that the TS mentioned populating the dropdown from the database, it's very unlikely that SelectedValue is actually a string.
More than likely, ValueMember is bound to the Id of the record in the database, DisplayMember is bound to some Description.
C#
object val = ((ComboBox)sender).SelectedValue; // returns the Id
string txt = ((ComboBox)sender).SelectedText; // returns the text visible on the screen for the selected item
object item = ((ComboBox)sender).SelectedItem; // returns the entire object from the datasource you have bound to the combobox

Depending on your needs, use any of these to retrieve/show further data.
 
Share this answer
 

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