Ecco questa è la pagina sceglilegale.aspx la parte dei due DropDownList
Questa la pagina con il code-behindcodice:<div id="legale1"> <ASP:Textbox id="lblstr_IdLegaleAffid" runat="server"></ASP:Textbox> </div> <div id="legale2"> Categoria: <asp:DropDownList ID="categoriaList" DataTextField="DescrCategoria" DataValueField="IDcategoria" OnSelectedIndexChanged="catelistChange" runat="server" /> Specializzazione: <asp:DropDownList ID="specializzazioneList" DataTextField="DescrSpecializzazione" DataValueField="IDspecializzazione" runat="server" > </asp:DropDownList>
codice:Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then 'Popolo il primo dropdownlist Dim MyConnection07 As OleDbConnection MyConnection07 = New OleDbConnection("Provider=SQLOLEDB; Data Source=ESCZ-NA-00; Integrated Security=SSPI; Initial Catalog=ContenziosoEsattoriale") MyConnection07.Open() Dim strSQL07 As String = "SELECT IDCategoria, DescrCategoria FROM TabcategoriaProf" Dim objCommand07 As New OleDbCommand(strSQL07, MyConnection07) Dim objDataReader07 As OleDbDataReader objDataReader07 = objCommand07.ExecuteReader(CommandBehavior.CloseConnection) categoriaList.DataSource = objDataReader07 categoriaList.DataTextField = "DescrCategoria" categoriaList.DataValueField = "IDCategoria" categoriaList.DataBind() Validate() end if 'popolo il secondo dropdownlist Protected Sub cateListChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles categoriaList.SelectedIndexChanged 'Dim lbl_dropdown1 As String = Me.categoriaList.SelectedValue() Dim lbl_dropdown1 As String = categoriaList.Items(categoriaList.SelectedIndex).Value Dim MyConnection08 As OleDbConnection MyConnection08 = New OleDbConnection("Provider=SQLOLEDB; Data Source=ESCZ-NA-00; Integrated Security=SSPI; Initial Catalog=ContenziosoEsattoriale") MyConnection08.Open() Dim strSQL08 As String = "SELECT IdSpecializzazione, DescrSpecializ FROM TabSpecializzazione Where IdCategoria = " & lbl_dropdown1 Dim objCommand08 As New OleDbCommand(strSQL08, MyConnection08) Dim objDataReader08 As OleDbDataReader objDataReader08 = objCommand08.ExecuteReader(CommandBehavior.CloseConnection) specializzazioneList.DataSource = objDataReader08 specializzazioneList.DataTextField = "DescrSpecializ" specializzazioneList.DataValueField = "IdSpecializzazione" specializzazioneList.DataBind() Validate() End Sub
Grazie

Rispondi quotando