hola banda, mi duda es la siguiente tengo un dropdownlist ya predefinido, y en base a ese dropdownlist ago la consulta a otro dropdownlist que lleno con una base de datos, y dependiendo de esa base de datos es otra consulta para otros campos. Lo que pasa esque al momento de hacer otra consulta me hace un auto increment en el dropdownlist, y se esta incrementando pero si le quito el atuposbak no se me incrementa pero me marca error de que esta nulo aqui esta el codigo.
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
Dim ds As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New SqlConnection("Data Source=xx;Initial Catalog=pruebas; User ID=do; Password=do")
MyConnection.Open()
MyCommand = New SqlDataAdapter("select id,mar from inmaprecomycom where dep ='" & DropDownList2.SelectedItem.Value & "'", MyConnection)
ds = New DataSet()
MyCommand.Fill(ds, "inmaprecomycom")
DropDownList2.DataSource = ds.Tables("inmaprecomycom").DefaultView
DropDownList2.DataTextField = "mar"
DropDownList2.DataValueField = "id"
DropDownList2.DataBind()
TextBox1.Text = DropDownList2.SelectedItem.ToString
MyConnection.Close()
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim ds As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New SqlConnection("Data Source=xx;Initial Catalog=pruebas; User ID=do; Password=do")
MyConnection.Open()
MyCommand = New SqlDataAdapter("select id,mar from inmaprecomycom where dep ='" & DropDownList1.SelectedItem.Value & "'", MyConnection)
ds = New DataSet()
MyCommand.Fill(ds, "inmaprecomycom")
DropDownList2.DataSource = ds.Tables("inmaprecomycom").DefaultView
DropDownList2.DataTextField = "mar"
DropDownList2.DataValueField = "id"
DropDownList2.DataBind()
TextBox1.Text = DropDownList2.SelectedIndex
MyConnection.Close()
End Sub
<title>Página sin título</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
Height="23px" Width="192px">
<asp:ListItem>INSTRUMENTACIÓN Y CO</asp:ListItem>
<asp:ListItem>ELÉCTRICO</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<br />
<asp:DropDownList ID="DropDownList2" runat="server"
AutoPostBack="True" Height="22px" Width="194px"
AppendDataBoundItems="True">
</asp:DropDownList>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>