Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

WANSELMO

Ajax .NET e ListBox

Recommended Posts

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

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.