Hello every one,
I have 5 combobox boxex.. contains 5 hard-code values say "name","city","phone","state","country". I have lable below that.
I want to display selected values of combobox in sequence, in lable.
Example: name-city-phone-state-country
Now if from second combobox if someone selects state then it should display as
name-state-city-phone-country..
Loading
Kirtan PatelPosted Oct 6, 2009, 4:44 AM
Here is Code i Wrote ( Tested And Working :) )
dont forget to mark "Do you like this answer" please it will give me some credits :)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Make All Combobox to Default 1 st value Selected at Load
comboBox1.SelectedIndex = 0;
comboBox2.SelectedIndex = 0;
comboBox3.SelectedIndex = 0;
comboBox4.SelectedIndex = 0;
comboBox5.SelectedIndex = 0;
}
private void Form1_Load(object sender, EventArgs e)
{
// Set Event Handler to Handle All combox Event into One Method :)
comboBox1.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
comboBox2.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
comboBox3.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
comboBox4.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
comboBox5.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
}
public void comboBox_SelectedIndexChanged(Object Sender,EventArgs e)
{
string[] x = new string[5];
x[0] = comboBox1.SelectedItem.ToString();
x[1] = comboBox2.SelectedItem.ToString();
x[2] = comboBox3.SelectedItem.ToString();
x[3] = comboBox4.SelectedItem.ToString();
x[4] = comboBox5.SelectedItem.ToString();
//Show In Label
label1.Text = "";
foreach (string str in x)
{
label1.Text += str + "-";
}
}
Thank you :)
chetan bhattadPosted Oct 6, 2009, 5:26 AM
Thanks a ton..
thats working for me..
Nice solution..
Deepak BhatiaPosted Oct 6, 2009, 3:03 AM
Gaurish KumarPosted Oct 6, 2009, 3:01 AM
try this
Code for aspx page:
<table>
<tr>
<td>
<asp:DropDownList ID="DropDownListName" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownListName_SelectedIndexChanged">
<asp:ListItem Text="Chetan" Value="Chetan" Selected="True">asp:ListItem>
<asp:ListItem Text="Ajay" Value="Ajay">asp:ListItem>
<asp:ListItem Text="Peter" Value="Peter">asp:ListItem>
<asp:ListItem Text="William" Value="William">asp:ListItem>
<asp:ListItem Text="Brown" Value="Brown">asp:ListItem>
asp:DropDownList>
td>
tr>
<tr>
<td>
<asp:DropDownList ID="DropDownListCity" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownListCity_SelectedIndexChanged">
<asp:ListItem Text="Delhi" Value="Delhi" Selected="True">asp:ListItem>
<asp:ListItem Text="Mumbai" Value="Mumbai">asp:ListItem>
<asp:ListItem Text="Lucknow" Value="Lucknow">asp:ListItem>
<asp:ListItem Text="Kolkatta" Value="Kolkatta">asp:ListItem>
<asp:ListItem Text="Bangalore" Value="Bangalore">asp:ListItem>
asp:DropDownList>
td>
tr>
<tr>
<td>
<asp:DropDownList ID="DropDownListPhone" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownListPhone_SelectedIndexChanged">
<asp:ListItem Text="123456" Value="123456" Selected="True">asp:ListItem>
<asp:ListItem Text="123457" Value="123457">asp:ListItem>
<asp:ListItem Text="123458" Value="123458">asp:ListItem>
<asp:ListItem Text="123459" Value="123459">asp:ListItem>
<asp:ListItem Text="123462" Value="123462">asp:ListItem>
asp:DropDownList>
td>
tr>
<tr>
<td>
<asp:DropDownList ID="DropDownListState" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownListState_SelectedIndexChanged">
<asp:ListItem Text="Delhi" Value="Delhi" Selected="True">asp:ListItem>
<asp:ListItem Text="Uttar Pradesh" Value="Uttar Pradesh">asp:ListItem>
<asp:ListItem Text="Maharastra" Value="Maharastra">asp:ListItem>
<asp:ListItem Text="Karnataka" Value="Karnataka">asp:ListItem>
<asp:ListItem Text="West Bengal" Value="West Bengal">asp:ListItem>
asp:DropDownList>
td>
tr>
<tr>
<td>
<asp:DropDownList ID="DropDownListCountry" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownListCountry_SelectedIndexChanged">
<asp:ListItem Text="India" Value="India" Selected="True">asp:ListItem>
<asp:ListItem Text="Pakistan" Value="Pakistan">asp:ListItem>
<asp:ListItem Text="USA" Value="USA">asp:ListItem>
<asp:ListItem Text="UK" Value="UK">asp:ListItem>
<asp:ListItem Text="Australia" Value="Australia">asp:ListItem>
asp:DropDownList>
td>
tr>
<tr>
<td>
<asp:Label ID="LabelResult" runat="server">asp:Label>
td>
tr>
table>
Code For aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
LabelResult.Text = DropDownListName.SelectedValue + " - " + DropDownListCity.SelectedValue + " - " + DropDownListPhone.SelectedValue + " - " + DropDownListState.SelectedValue + " - " + DropDownListCountry.SelectedValue;
}
protected void DropDownListName_SelectedIndexChanged(object sender, EventArgs e)
{
LabelResult.Text = DropDownListName.SelectedValue + " - " + DropDownListCity.SelectedValue + " - " + DropDownListPhone.SelectedValue + " - " + DropDownListState.SelectedValue + " - " + DropDownListCountry.SelectedValue;
}
protected void DropDownListCity_SelectedIndexChanged(object sender, EventArgs e)
{
LabelResult.Text = DropDownListName.SelectedValue + " - " + DropDownListCity.SelectedValue + " - " + DropDownListPhone.SelectedValue + " - " + DropDownListState.SelectedValue + " - " + DropDownListCountry.SelectedValue;
}
protected void DropDownListPhone_SelectedIndexChanged(object sender, EventArgs e)
{
LabelResult.Text = DropDownListName.SelectedValue + " - " + DropDownListCity.SelectedValue + " - " + DropDownListPhone.SelectedValue + " - " + DropDownListState.SelectedValue + " - " + DropDownListCountry.SelectedValue;
}
protected void DropDownListState_SelectedIndexChanged(object sender, EventArgs e)
{
LabelResult.Text = DropDownListName.SelectedValue + " - " + DropDownListCity.SelectedValue + " - " + DropDownListPhone.SelectedValue + " - " + DropDownListState.SelectedValue + " - " + DropDownListCountry.SelectedValue;
}
protected void DropDownListCountry_SelectedIndexChanged(object sender, EventArgs e)
{
LabelResult.Text = DropDownListName.SelectedValue + " - " + DropDownListCity.SelectedValue + " - " + DropDownListPhone.SelectedValue + " - " + DropDownListState.SelectedValue + " - " + DropDownListCountry.SelectedValue;
}