2014年5月24日 星期六

ASP.NET Combobox Sample

ASP.NET Combobox Sample
DropDownList TextBox


HTML:
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head runat="server">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  4. <title></title>
  5. <style type="text/css">
  6. .t1
  7. {
  8. width:200px;
  9. position:absolute;
  10. }
  11. .d1
  12. {
  13. width:217px;
  14. height:22px;
  15. clip:rect(auto auto auto 200px);
  16. position:absolute;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <form id="form1" runat="server">
  22. <div>
  23. <asp:TextBox ID="TextBox1" runat="server" CssClass="t1" ></asp:TextBox>
  24. <asp:DropDownList ID="DropDownList1" runat="server" CssClass="d1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
  25. <asp:ListItem Text="a" Value="1"></asp:ListItem>
  26. <asp:ListItem Text="b" Value="2"></asp:ListItem>
  27. <asp:ListItem Text="c" Value="3"></asp:ListItem>
  28. </asp:DropDownList>
  29. </div>
  30. </form>
  31. </body>
  32. </html>

C#:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. public partial class Test_tsCombobox : System.Web.UI.Page
  9. {
  10. protected void Page_Load(object sender, EventArgs e)
  11. {
  12.  
  13. }
  14. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  15. {
  16. TextBox1.Text = DropDownList1.SelectedItem.Text;
  17. }
  18. }

沒有留言:

張貼留言