The page markup, there's no codebehind:
<asp:SqlDataSource 
	Id="SqlDataSource1" 
	runat="server" 
	ConnectionString="<%$ ConnectionStrings:FooConnectionString %>"
	SelectCommand="select distinct [Id], [Name] FROM [City] ORDER BY [Name]">
</asp:SqlDataSource>
<p>
	<asp:Label runat="server" Text="Select city" />
	<br />
	<asp:DropDownList 
		Id="cityDropDownList" 
		runat="server" 
		DataSourceID="SqlDataSource1" 
		DataTextField="Name" 
		DataValueField="Id" 
		AutoPostBack="True"
	/>
</p>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
	ConnectionString="<%$ ConnectionStrings:FooConnectionString %>" 
	SelectCommand="SELECT [Id], [Name] FROM [Town] WHERE ([CityId] = @Id) ORDER BY [Name]">
	<SelectParameters>
		<asp:ControlParameter 
			ControlID="cityDropDownList" 
			Name="id" 
			PropertyName="SelectedValue" 
			Type="String" 
		/>
	</SelectParameters>
</asp:SqlDataSource>
<p>
	<asp:Label runat="server" Text="Select town" />
	<br />
	<asp:DropDownList 
		ID="townDropDownList" 
		runat="server" 
		DataSourceID="SqlDataSource2" 
		DataTextField="Name" 
		DataValueField="Id">
	</asp:DropDownList>
</p>

Last edited Aug 10, 2011 at 7:25 AM by teoarch, version 1

Comments

No comments yet.