Click here to Skip to main content
15,924,829 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi folks
I need some help

I have two combobox 1.Area 2.Route
I have to show the result of two combobox on label as so.how it will be possible?

Help me..

Thnxx in advance
Posted

The following piece of code will help you. . .(Will Be Helpful in WINDOWS APPLICATION)

Suppose i have two combobox.
Area as Combobox1
Route as Combobox2

Now set Text Property of Combobox1 and Combobox2 to whatever you want.

C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
        label1.Text = "";
        label1.Text = comboBox1.SelectedItem.ToString() + " : " + comboBox2.SelectedItem.ToString();
}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
        label1.Text = "";
        label1.Text = comboBox1.SelectedItem.ToString() + " : " + comboBox2.SelectedItem.ToString();
}
 
Share this answer
 
Please find you Solution.

first use

if(!IsPostBack )
{
}
in your Page Load and then try with below code




C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
        label1.Text =label1.Text +" "+ comboBox1.SelectedItem.Text;
}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
        label1.Text =label1.Text +" "+  comboBox2.SelectedItem.Text;
}
 
Share this answer
 
Hi Indrajeet,

Try following code.
As you have two drops
Area and Route

Aspx Code
ASP.NET
<asp:dropdownlist runat="server" xmlns:asp="#unknown">
ID="dropdownArea"  
onselectedindexchanged="dropdown_SelectedIndexChanged" 
AutoPostBack="true"    />

<asp:dropdownlist runat="server">
ID="dropdownRoute"  
onselectedindexchanged="dropdown_SelectedIndexChanged"  
AutoPostBack="true" >
</asp:dropdownlist></asp:dropdownlist>


Code Behind
C#
protected void dropdown_SelectedIndexChanged(object sender, EventArgs e)
{
      SetLabelText();
}

private void SetLabelText()
{
 lbltext.Text  = String.Format("{0}-{1}",dropdownArea.SelectedItem.Text,dropdownRoute.SelectedItem.Text);
}


Hope this help!
 
Share this answer
 
Hi Techie,

Suppose the Comboboxes are named as ComboBox1 and ComboBox2.

Get the selected values of combobox and do a string concatenation.


Lable1.Text =
String.Concat(ComboBox1.SelectedItem.toString(),ComboBox2.SelectedItem.toString())

Make sure that you do the validation before casting the selecteditem toString().

I hope this is what you are looking for.

Happy Coding!!!
 
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