As i said before, use this as something to understand your mistakes and build on it. This is just a sample of how you could do it. I would be happy if you understand something out of this!
ASPX Markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="SampleWebApp.test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="dd1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dd1_Changed"></asp:DropDownList>
<br />
<asp:DropDownList ID="dd2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dd2_Changed"></asp:DropDownList>
<br />
<asp:Label ID="lbl1" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
C# code-behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SampleWebApp
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
dd1.DataSource = Data.GetSource(5);
dd1.DataTextField = "Text";
dd1.DataValueField = "Value";
dd1.DataBind();
}
}
protected void dd1_Changed(object sender, EventArgs e)
{
dd2.DataSource = Data.GetSource(int.Parse(dd1.SelectedValue));
dd2.DataTextField = "Text";
dd2.DataValueField = "Value";
dd2.DataBind();
}
protected void dd2_Changed(object sender, EventArgs e)
{
lbl1.Text = dd1.SelectedValue.ToString() + " - " + dd2.SelectedValue.ToString();
}
}
public class Data
{
public string Text { get; set; }
public int Value { get; set; }
public static List<Data> GetSource(int n)
{
List<Data> d = new List<Data>();
Enumerable.Range(1, n).ToList().ForEach(delegate(int i)
{
Data dd = new Data { Text = i.ToString(), Value = i };
d.Add(dd);
});
return d;
}
}
}
Hope this helps! Do let me (us) know if you have any questions!