DropDownList - editável

<< Click to Display Table of Contents >>

Navigation:  ASP.NET > ASP Controls >

DropDownList - editável

Previous pageReturn to chapter overviewNext page

Tela

 

Um dropdown que permite editar ou escolher um item na lista

 

 

ddleditavel

 

Default.aspx

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %>

 

<!DOCTYPE html>

<head runat="server">

  <script type="text/javascript">

      function DisplayText() {

          var empresa = document.getElementById("<%=ddSelect.ClientID%>");

          var texto = empresa.options[empresa.selectedIndex].text;

          var edit = document.getElementById("<%=txtDisplay.ClientID%>");

           edit.value = texto;

           edit.focus();

       }

  </script>

</head>

<body>

  <form id="form1" runat="server">

  <div>

      <asp:TextBox Style="width: 120px; position: absolute" ID="txtDisplay" runat="server"></asp:TextBox>

      <asp:DropDownList ID="ddSelect" Style="width: 150px" runat="server">

          <asp:ListItem Value="test1">test1</asp:ListItem>

          <asp:ListItem Value="test2">test2</asp:ListItem>

      </asp:DropDownList>

  </div>

  </form>

</body>

</html>

 

Default.aspx.cs

 

using System;

 

public partial class Default : System.Web.UI.Page

{

  protected void Page_Load(object sender, EventArgs e)

   {

       ddSelect.Attributes.Add("onChange", "DisplayText();");

   }

}

 

Fonte

 

http://www.codeproject.com/Articles/30877/Editable-DropDownlist