Here is a small example that you could follow
<asp:dropdownlist id="DropDownList1" runat="server" xmlns:asp="#unknown">
onselectedindexchanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
Following is in .cs
public partial class DropDownListSelectedIndex : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.DataSource = DataClass2.getData();
DropDownList1.DataTextField = "s";
DropDownList1.DataValueField = "s2";
DropDownList1.DataBind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList dptList = (DropDownList)sender;
Label1.Text = dptList.SelectedIndex.ToString();
}
}
public class DataClass2
{
public string s { get; set; }
public string s2 { get; set; }
public static List<dataclass2> getData()
{
List<dataclass2> dataLst = new List<dataclass2>();
for (int i = 1; i <= 5; i++)
{
DataClass2 data = new DataClass2();
data.s = "S" + i;
data.s2 = "M" + i;
dataLst.Add(data);
}
return dataLst;
}
}</dataclass2></dataclass2></dataclass2>