ListBox Event(index change)
index change event when we select the value.
step1
eg.1.UG
2.PG
3.Select
Step2
make two listBox

Any listbox in which event occur make autoPostBack as true othewise it is false.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class listboxugpg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (ListBox2.Text == "UG")
{
ListBox3.Items.Clear();
ListBox3.Items.Add("CSE");
ListBox3.Items.Add("CT");
ListBox3.Items.Add("ETC");
ListBox3.Items.Add("Mechanical");
ListBox3.Items.Add("ETRX");
ListBox3.Items.Insert(0,"select");
}
if (ListBox2.Text == "PG")
{
ListBox3.Items.Clear();
ListBox3.Items.Add("MBA");
ListBox3.Items.Add("MCA");
ListBox3.Items.Add("MTECH");
ListBox3.Items.Insert(0,"select");
}
}
}
Note:
1) ListBox.Items.Clear();
It merge data for resolve the problem
2) ListBox.Items.Insert(0,"select");
0-position
select-value on position 0.
For inserting the value on position 0.
step1
eg.1.UG
2.PG
3.Select
Step2
make two listBox

Any listbox in which event occur make autoPostBack as true othewise it is false.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class listboxugpg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (ListBox2.Text == "UG")
{
ListBox3.Items.Clear();
ListBox3.Items.Add("CSE");
ListBox3.Items.Add("CT");
ListBox3.Items.Add("ETC");
ListBox3.Items.Add("Mechanical");
ListBox3.Items.Add("ETRX");
ListBox3.Items.Insert(0,"select");
}
if (ListBox2.Text == "PG")
{
ListBox3.Items.Clear();
ListBox3.Items.Add("MBA");
ListBox3.Items.Add("MCA");
ListBox3.Items.Add("MTECH");
ListBox3.Items.Insert(0,"select");
}
}
}
Note:
1) ListBox.Items.Clear();
It merge data for resolve the problem
2) ListBox.Items.Insert(0,"select");
0-position
select-value on position 0.
For inserting the value on position 0.