C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (DBEntities dc = new DBEntities())
{
ddlYear.DataSource = dc.Subjects.Select(s => s.Year).Distinct().ToList();
ddlYear.DataBind();
}
}
}
protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
{
int year = Convert.ToInt32(ddlYear.Text);
using (DBEntities dc = new DBEntities())
{
ListViewSubjects.DataSource = dc.Subjects.Where(s=> s.Year == year) .Distinct().ToList();
ListViewSubjects.DataBind();
}
}
ASPX
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlYear" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlYear_SelectedIndexChanged"></asp:DropDownList>
<br />
<asp:ListView ID="ListViewSubjects" runat="server">
<ItemTemplate>
<asp:Label ID="NameLabel" runat="server"
Text='<%#Eval("Name") %>' />
</ItemTemplate>
</asp:ListView>
</div>
</form>