<asp:DropDownList ID="ddlAppClass" runat="server" AutoPostBack="True" Height="20px" Width="188px" OnSelectedIndexChanged="ddlAppClass_SelectedIndexChanged" EnableViewState="true"></asp:DropDownList>
<asp:TextBox ID="txtDateOfBirth" OnTextChanged="txtDateOfBirth_TextChanged" AutoPostBack="true" runat="server" />
Selected item: <asp:Literal ID="LiteralResult" runat="server" />
code-behind
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string query = string.Format("SELECT [Teaching Room Category] ,[Description] FROM [Corona Schools_ Trust Council$Teaching Room Level] WHERE [Teaching Room Category] = '{0}'", "NURSERY");
BindDropDownList(this.ddlAppClass, query, "Description", "Teaching Room Category", "---Select---");
}
}
private void BindDropDownList(DropDownList ddl, string query, string text, string value, string defaultText)
{
ddl.Items.Add(new ListItem { Text = "One", Value = "1" });
ddl.Items.Add(new ListItem { Text = "Two", Value = "2" });
ddl.Items.Add(new ListItem { Text = "Three", Value = "3" });
ddl.Items.Insert(0, new ListItem(defaultText, "0"));
}
protected void ddlAppClass_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void txtDateOfBirth_TextChanged(object sender, EventArgs e)
{
if (this.ddlAppClass.SelectedIndex != 0)
{
LiteralResult.Text = this.ddlAppClass.SelectedItem.Text;
}
}