WANSELMO 0 Denunciar post Postado Janeiro 28, 2009 Pessoal, estou começando a estudar Ajax e tenho uma duvida: Tenho uma pagina que tem um ListBox e preciso que simplesmente exiba o Text do item selecionado em um TextBox. Aparentemente fácil, mas com ajax não consegui... Onde está o problema ? Segue o codigo : <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager2" EnablePartialRendering="true" runat="server"> </asp:ScriptManager> <div> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> <asp:DropDownList ID="DropDownList1" runat="server" onselectedindexchanged="cboItens_SelectedIndexChanged"> </asp:DropDownList> </div> </div> </form> </body> </html> [b]No .cs :[/b] using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1 { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DropDownList1.Items.Add(new ListItem("-")); DropDownList1.Items.Add(new ListItem("Mulher")); DropDownList1.Items.Add(new ListItem("Homem")); } } protected void cboItens_SelectedIndexChanged(object sender, EventArgs e) { TextBox2.Text = DropDownList1.SelectedItem.Text; } } } Poderiam me ajudar ? Grato ! Compartilhar este post Link para o post Compartilhar em outros sites
DSerma 19 Denunciar post Postado Janeiro 29, 2009 Movido: AJAX http://forum.imasters.com.br/public/style_emoticons/default/seta.gif Plataforma .NET » Web Applications Compartilhar este post Link para o post Compartilhar em outros sites
quintelab 91 Denunciar post Postado Janeiro 29, 2009 Você deve definir a propriedade AutoPostBack como true do DropDownList. Abraços... Compartilhar este post Link para o post Compartilhar em outros sites