<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>Binding to a Property of a Server Control</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server" src="~/shared/fetchData_sql.cs" />
<script language="C#" runat="server">
void Page_Load ( Object sender, EventArgs e ) {
if ( !IsPostBack ) {
string query = "SELECT StateName FROM States WHERE CountryCode='US' ORDER BY StateName";
lstStates.DataSource = fetchData ( query );
lstStates.DataBind ( );
}
}
void getState ( Object sender, EventArgs e ) {
Page.DataBind ( );
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>Binding to a Property of a Server Control</h2></div>
<hr size=1 width=92%>
<center>
<form runat="server">
<asp:dropdownlist id="lstStates" runat="server"
datatextfield="statename" />
<asp:button text="Submit" onClick="getState" runat="server" />
<p>Selected State: <b><asp:label text='<%# lstStates.Text %>' runat="server" /></b>
</form>
</center>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>