2009-10-24 78 views

回答

1

這是一個jquery插件,用於轉換客戶端。你沒有標記你的問題來表明你正在使用哪種服務器端技術,但是從你的描述中我推斷它是ASP.NET。

下面是一個示例頁面我設置說明如何實現你正在尋找的功能:

<%@ Page Language="C#" %> 
<%@ Import Namespace="System.Linq" %> 

<script type="text/C#" runat="server"> 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      listBox.DataSource = new[] { "Aries", "Taurus", "Gemini" }; 
      listBox.DataBind(); 
     } 
    } 

    protected void BtnClick(object sender, EventArgs e) 
    { 
     var selectedItems = (from item in listBox.Items.Cast<ListItem>() 
       where item.Selected 
       select item.Text).ToArray(); 
     result.Text = "You selected: "; 
     result.Text += string.Join(",", selectedItems); 
    } 
</script> 
<!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> 
    <script type="text/javascript" src="scripts/jquery.js"></script> 
    <script type="text/javascript" src="scripts/ui.core.js"></script> 
    <script type="text/javascript" src="scripts/ui.dropdownchecklist.js"></script> 
    <script type="text/javascript"> 
     $(function() { 
      $('.listBox').dropdownchecklist(); 
     }); 
    </script> 
    <link rel="stylesheet" href="css/ui.dropdownchecklist.css" /> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:ListBox ID="listBox" runat="server" SelectionMode="Multiple" CssClass="listBox" /> 
     <asp:LinkButton ID="btn" runat="server" Text="Click me" OnClick="BtnClick" /> 
     <asp:Label ID="result" runat="server" /> 
    </div> 
    </form> 
</body> 
</html> 
+0

感謝達林季米特洛夫。我從很久以前就在尋找這個代碼。它的工作正常,因爲我想要的。 如果我需要在這裏進行像這樣的功能。至少用戶應該選擇一個值,即複選框如何做到這一點 – happysmile 2009-10-24 17:19:19

+0

我在做c#,asp.net服務器端事件 – happysmile 2009-10-26 09:15:08