Estou tentando mandar informação de um drodownlist para o outro, no primeiro recebo os dados, ate consigo mandar par auma label, ou text box, porem para um outro droplist nao funciona, se alguem puder ajudar, seria algo tipo no primeiro recebo o nome, dai no segundo recebo alguma informação que referente no banco de dados, tipo endereco e, tipo como se fosse um filtro mesmo.
<%@ Page Language="vb" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
Dim strConexao as String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\wwwroot\asp.net\Felipe\cadastro.mdb"
Dim strSQL As String
Dim conexao As New OleDbConnection()
Dim comando as New OleDbCommand()
Dim tabela as OleDbDataReader
Sub Page_Load(obj as object, e as eventargs)
if not Page.IsPostBack then
abastece()
end if
end sub
sub abastece()
conexao.ConnectionString = strConexao
strSQl = "SELECT * FROM cadastro " & _
"ORDER BY NOME"
comando.CommandText = strSQL
comando.Connection = conexao
conexao.open()
tabela = comando.ExecuteReader
lbCategoria.DataSource = tabela
lbCategoria.DataValueField = "codigo"
lbCategoria.DataTextField = "nome"
lbCategoria.DataBind()
Conexao.Close
End Sub
Sub Select_Categoria(obj as object, e as eventargs)
conexao.ConnectionString = strConexao
strSQl = "SELECT * FROM cadastro " & _
"WHERE codigo = " & lbCategoria.SelectedItem.Value
comando.CommandText = strSQL
comando.Connection = conexao
conexao.open
tabela = comando.ExecuteReader
If tabela.Read then
lblCodigo.text = tabela.getvalue(0)
tbCategoria.text = tabela.getvalue(1)
tbDescricao.text = tabela.getvalue(5)
Aqui coloco como nos outros recebedrop.text = tabela.getvalue(6), porem nao funciona
end if
end sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
</p>
<asp:DropDownList id="lbCategoria" runat="server" autopostback="True" onselectedindexchanged="Select_Categoria"></asp:DropDownList>
<asp:DropDownList id="recebedrop" runat="server" autopostback="True" ></asp:DropDownList>
<asp:Label id="lblCodigo" runat="server" readonly="true"></asp:Label>
<br />
<asp:TextBox id="tbDescricao" runat="server"></asp:TextBox>
<p>
<asp:textBox id="tbCategoria" runat="server"></asp:textBox>
</p>
</form>
</body>
</html>
De Uma Dropdwonlist Para Outro
Started By fsq2, 10/05/2004, 00:26
8 replies to this topic
#1
Posted 10/05/2004, 00:26
#2
Posted 10/05/2004, 09:57
*************** M ** A ** C ** U ** L ***************
*************************************************
*************************************************
#3
Posted 10/05/2004, 10:18
se vc quer preencher o drop, basta vc usar a mesma rotina q usou no anterior
abraços
t+
abraços
t+
#4
Posted 10/05/2004, 12:23
Entao mais eu quero receber do outro Drop
#5
Posted 10/05/2004, 12:35
repete isso cara:
abraços
t+
conexao.ConnectionString = strConexao strSQL = "SELECT * FROM cadastro WHERE codigo ="& Request("lbCategoria") comando.CommandText = strSQL comando.Connection = conexao conexao.open() tabela = comando.ExecuteReader recebedrop.DataSource = tabela recebedrop.DataValueField = "codigo" recebedrop.DataTextField = "nome" recebedrop.DataBind() Conexao.Close
abraços
t+
#6
Posted 11/05/2004, 00:32
Fala serio to te enchendo em rsrsrs.
Da maneira que você me disse rolou, mais olha so o que quero acho que consegui explicar melhor
Entao vou ver se te explico melhor.
Recebi os dados no primeiro DropList, ate ai blz, quando clico nele ele envia para o segundo droplist.
POr exemplo no primeiro drop tem a lista de categorias de progutos (informatica), dai no segundo aparece todos os intens dessa categoria.
Oque você segere.
Eu sei que por exemplo
recebedrop.DataValueField = "codigo" vem o valor que vai no Drop
recebedrop.DataTextField = "nome" Aqui o Text
Como você me falou no codigo acima, eu consigo receber um valor so, tem como receber a lista um lista por exemplo
Da maneira que você me disse rolou, mais olha so o que quero acho que consegui explicar melhor
Entao vou ver se te explico melhor.
Recebi os dados no primeiro DropList, ate ai blz, quando clico nele ele envia para o segundo droplist.
POr exemplo no primeiro drop tem a lista de categorias de progutos (informatica), dai no segundo aparece todos os intens dessa categoria.
Oque você segere.
Eu sei que por exemplo
recebedrop.DataValueField = "codigo" vem o valor que vai no Drop
recebedrop.DataTextField = "nome" Aqui o Text
Como você me falou no codigo acima, eu consigo receber um valor so, tem como receber a lista um lista por exemplo
#7
Posted 11/05/2004, 09:46
parece que vc quer o código pronto, pq o que vc esta pedindo foi o que fiz e esta no link
http://www.macul.eti...ombosiguais.htm
Código carrega 2 combos iguais
Arquivo 2combosiguais.aspx.vb
Public Class _2combosiguais
Inherits System.Web.UI.Page
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim i As Integer
For i = 0 To DropDownList1.Items.Count() - 1
DropDownList2.Items.Add(New ListItem(DropDownList1.Items(i).Text, DropDownList1.Items(i).Value))
Next
End Sub
End Class
Arquivo 2combosiguais.aspx
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" runat="server" >
<asp:ListItem Value=1>Texto1</asp:ListItem>
<asp:ListItem Value=2>Texto2>/asp:ListItem>
<asp:ListItem Value=3>Texto3</asp:ListItem>
<asp:ListItem Value=4>Texto4</asp:ListItem>
<asp:ListItem Value=5>Texto5</asp:ListItem>
<asp:ListItem Value=6>Texto6</asp:ListItem>
<asp:ListItem Value=7>Texto7</asp:ListItem>
<asp:ListItem Value=8>Texto8</asp:ListItem>
<asp:ListItem Value=9>Texto9</asp:ListItem>
<asp:ListItem Value=0>Texto0</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList id="DropDownList2" runat="server" ></asp:DropDownList>
</form>
http://www.macul.eti...ombosiguais.htm
Código carrega 2 combos iguais
Arquivo 2combosiguais.aspx.vb
Public Class _2combosiguais
Inherits System.Web.UI.Page
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim i As Integer
For i = 0 To DropDownList1.Items.Count() - 1
DropDownList2.Items.Add(New ListItem(DropDownList1.Items(i).Text, DropDownList1.Items(i).Value))
Next
End Sub
End Class
Arquivo 2combosiguais.aspx
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" runat="server" >
<asp:ListItem Value=1>Texto1</asp:ListItem>
<asp:ListItem Value=2>Texto2>/asp:ListItem>
<asp:ListItem Value=3>Texto3</asp:ListItem>
<asp:ListItem Value=4>Texto4</asp:ListItem>
<asp:ListItem Value=5>Texto5</asp:ListItem>
<asp:ListItem Value=6>Texto6</asp:ListItem>
<asp:ListItem Value=7>Texto7</asp:ListItem>
<asp:ListItem Value=8>Texto8</asp:ListItem>
<asp:ListItem Value=9>Texto9</asp:ListItem>
<asp:ListItem Value=0>Texto0</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList id="DropDownList2" runat="server" ></asp:DropDownList>
</form>
*************** M ** A ** C ** U ** L ***************
*************************************************
*************************************************
#8
Posted 11/05/2004, 18:56
Entao, mais nao sao dois Drops iguais,
Um Recebe tipo categoria(Informatica), e o outro recebe os item da Categoria (Informatica).
Um Recebe tipo categoria(Informatica), e o outro recebe os item da Categoria (Informatica).
#9
Posted 12/05/2004, 10:26
veja bem, já foi esclarecido, vamos fazer uma coisa. Insere a estrutura das suas tabelas, que fica + fácil p/ vc entender qdo explicarmos.
T +
MACUL
T +
MACUL
*************** M ** A ** C ** U ** L ***************
*************************************************
*************************************************
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)