日期:2014-05-18 浏览次数:20459 次
<asp:DropDownList ID="lstCls" runat ="server" AutoPostBack ="True" Width ="200px" DataSourceID="dataProductCls" DataTextField="Class" DataValueField="ID"/> <br /> <asp:DropDownList ID="lstSubCls" runat ="server" Width ="200" AutoPostBack ="true" />
Protected Sub lstCls_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles lstCls.SelectedIndexChanged Dim strSelected As String = lstCls.SelectedItem.Text dataProductSubCls.SelectParameters.Clear() dataProductSubCls.SelectParameters.Add("Selected", TypeCode.String, strSelected) dataProductSubCls.SelectCommand = "SELECT ProductCls.Class, ProductSubCls.ID, ProductSubCls.SubClass FROM ProductSubCls " & "INNER JOIN ProductCls ON ProductSubCls.Class = ProductCls.ID " & "WHERE ProductCls.Class = @Selected" lstSubCls.Enabled = True lstSubCls.DataSourceID = "dataProductSubCls" lstSubCls.DataTextField = "SubClass" lstSubCls.DataValueField = "ID" lstSubCls.DataBind() End Sub Protected Sub lstSubCls_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles lstSubCls.SelectedIndexChanged Dim strSelected As String = lstSubCls.SelectedItem.Text sqlComm = New SqlCommand("SELECT Pic, Alt FROM ProductSubCls WHERE SubClass = @Selected", sqlConn) sqlComm.Parameters.Add("@Selected", Data.SqlDbType.NVarChar, 50) sqlComm.Parameters("@Selected").Value = strSelected Try sqlConn.Open() reader = sqlComm.ExecuteReader If reader.Read Then ...'将内容附给其他控件 Else ...'执行其他代码 End If Catch ex As Exception Response.Write (ex.Message) Finally sqlConn.Close() End Try End Sub