2010-05-25 85 views
1

我有下面的代碼來實現一個帶複選框的下拉列表。我的問題是,每次我點擊一個複選框的下拉列表關閉,我需要重新打開它來選擇更多的複選框。我如何做到這一點,所以下拉列表dosn't關閉,直到我點擊它?如何防止ajax工具包DropDownExtender在點擊時關閉?

<asp:Panel ID="pnl_Items" runat="server" BorderColor="Aqua" BorderWidth="1"> 
     <asp:CheckBoxList ID="cbl_Items" runat="server"> 
      <asp:ListItem Text="Item 1" /> 
      <asp:ListItem Text="Item 2" /> 
      <asp:ListItem Text="Item 3" />   
     </asp:CheckBoxList> 
    </asp:Panel> 

    <br /> 
    <asp:TextBox ID="tb_Items" runat="server"></asp:TextBox> 
    <ajax:DropDownExtender ID="TextBox1_DropDownExtender" 
          runat="server" 
          DynamicServicePath="" 
          Enabled="True" 
          DropDownControlID="pnl_Items" on 
          TargetControlID="tb_Items"> 
    </ajax:DropDownExtender> 

回答

2

我能夠通過添加下面的JavaScript,我就this post發現,以獲得所需的行爲。

var DDE; 
function pageLoad() 
{ 
    DDE = $find('<%= TextBox1_DropDownExtender.ClientID %>'); 
    DDE._dropWrapperHoverBehavior_onhover(); 
    $get('<%= pnl_Items.ClientID %>').style.width = $get('<%= tb_Items.ClientID %>').clientWidth; 


    if (DDE._dropDownControl) { 
     $common.removeHandlers(DDE._dropDownControl, DDE._dropDownControl$delegates); 
    } 
    DDE._dropDownControl$delegates = { 
     click: Function.createDelegate(DDE, ShowMe), 
     contextmenu: Function.createDelegate(DDE, DDE._dropDownControl_oncontextmenu) 
    } 
    $addHandlers(DDE._dropDownControl, DDE._dropDownControl$delegates); 
} 

function ShowMe() { 
    DDE._wasClicked = true; 
} 
1

您將需要獲取Ajax控件工具包的源代碼並修改DropDownExtender的行爲,使其符合您的需要。每個控件都有自己的文件夾,其中包含所有與其功能相關的文件。

重新編譯,將新的dll放到您的項目中。

+0

我會看看那個。感謝領先。 – 2010-05-26 04:13:12

3

我不想改變AjaxControlToolkit。如下:

$(document).ready(function() { 
$('input[type=checkbox], label').click(function(e){ 
    if (!e) var e = window.event; 
    e.cancelBubble = true; 
    if (e.stopPropagation)e.stopPropagation(); 
}); 
}); 

將jquery選擇器更改爲您的複選框!

+0

這比上面的方法要乾淨得多。通過認真構建jquery選擇器,您可以實現所需的控件。謝謝。 – ravinsp 2010-06-29 08:43:51