1.重要的是思路: 2.代码:.aspx: <form id="Form1" method="post" runat="server"> <asp:DropDownList id="DDL1" Width="72px"></asp:DropDownList> <asp:DropDownList id="DDL2" runat="server" Width="160px"></asp:DropDownList> </form>.vb: Imports Microsoft.ApplicationBlocks.DataPrivate Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then bindDDL1() If DDL1.Items.Count <> 0 Then DDL1.AutoPostBack = True bindDDL2(DDL1.SelectedValue) End If End If End SubPrivate Sub bindDDL1() DDL1.DataSource = SqlHelper.ExecuteDataset(Func.NorthwindConnstr, CommandType.Text, "select top 5 customerId from Customers") DDL1.DataTextField = "customerId" DDL1.DataValueField = "customerId" DDL1.DataBind() End SubPrivate Sub bindDDL2(ByVal customerId As String) DDL2.DataSource = SqlHelper.ExecuteDataset(Func.NorthwindConnstr, CommandType.Text, "select top 5 orderId from orders where customerId='" & customerId & "' ") DDL2.DataTextField = "orderId" DDL2.DataValueField = "orderId" DDL2.DataBind() End SubPrivate Sub DDL1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDL1.SelectedIndexChanged bindDDL2(DDL1.SelectedValue) End Sub
2.代码:.aspx:
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DDL1" Width="72px"></asp:DropDownList>
<asp:DropDownList id="DDL2" runat="server" Width="160px"></asp:DropDownList>
</form>.vb:
Imports Microsoft.ApplicationBlocks.DataPrivate Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
bindDDL1()
If DDL1.Items.Count <> 0 Then
DDL1.AutoPostBack = True
bindDDL2(DDL1.SelectedValue)
End If
End If
End SubPrivate Sub bindDDL1()
DDL1.DataSource = SqlHelper.ExecuteDataset(Func.NorthwindConnstr, CommandType.Text, "select top 5 customerId from Customers")
DDL1.DataTextField = "customerId"
DDL1.DataValueField = "customerId"
DDL1.DataBind()
End SubPrivate Sub bindDDL2(ByVal customerId As String)
DDL2.DataSource = SqlHelper.ExecuteDataset(Func.NorthwindConnstr, CommandType.Text, "select top 5 orderId from orders where customerId='" & customerId & "' ")
DDL2.DataTextField = "orderId"
DDL2.DataValueField = "orderId"
DDL2.DataBind()
End SubPrivate Sub DDL1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDL1.SelectedIndexChanged
bindDDL2(DDL1.SelectedValue)
End Sub