RadComboBox与复选框

时间:2013-06-21 21:09:38

标签: asp.net telerik

我正在尝试在RadComboBoxItem中创建一组复选框。当点击组1我希望所有组1被选中并且对于组2都是相同的以及全部检查。(但是我希望能够对所有检查设置样式,所以我已经使它成为额外的选项)。所以这一切都运行正常,我唯一的问题是,当选择一个选项时,它会关闭下拉...我怎么能阻止它这样做呢?

组合框:

   EnableAutomaticLoadOnDemand="True" DropDownWidth="380px">
    <Items>
        <telerik:RadComboBoxItem runat="server" BackColor="Gray" ForeColor="White" 
                     Owner="txtAlertType" Text="Check All" Value="0" />
        <telerik:RadComboBoxItem runat="server" Text="Stop Payment Submitted" 
            Value="13" />
        <telerik:RadComboBoxItem runat="server" BackColor="DarkGray" IsSeparator="True" 
            Owner="txtAlertType" Text="Custom Alerts" Value="0" />
        <telerik:RadComboBoxItem runat="server" Text="Login" Value="12" />
        <telerik:RadComboBoxItem runat="server" Text="Matures in X Days" Value="1" />
        <telerik:RadComboBoxItem runat="server" BackColor="DarkGray" IsSeparator="True" 
            Owner="txtAlertType" Text="Cash Management" Value="0" />
        <telerik:RadComboBoxItem runat="server" Text="Payment Due in X Days" 
            Value="2" />
        <telerik:RadComboBoxItem runat="server" Text="Batch Approved" Value="21" />
        <telerik:RadComboBoxItem runat="server" Text="Balance &gt; $" Value="3" />
        <telerik:RadComboBoxItem runat="server" Text="Batch Prossed" Value="22" />
        <telerik:RadComboBoxItem runat="server" Text="Balance &lt; $" Value="4" />
        <telerik:RadComboBoxItem runat="server" Text="Positive Pay Exception" 
            Value="25" />
        <telerik:RadComboBoxItem runat="server" Text="Pending ACH" Value="5" />
        <telerik:RadComboBoxItem runat="server" Text="Bank Received Wire &gt; $" 
            Value="24" />
        <telerik:RadComboBoxItem runat="server" Text="Balance Alert" Value="6" />
        <telerik:RadComboBoxItem runat="server" Text="Wire Approved" Value="23" />
        <telerik:RadComboBoxItem runat="server" Text="Check # Cleared" Value="7" />
        <telerik:RadComboBoxItem runat="server" Text="Wire Submitted &gt; $" 
            Value="26" />
        <telerik:RadComboBoxItem runat="server" Text="Deposit &gt; $" Value="8" />
        <telerik:RadComboBoxItem runat="server" Text="Wire Transfer Rejected by User" 
            Value="27" />
        <telerik:RadComboBoxItem runat="server" Text="Debit &gt; $" Value="9" />
        <telerik:RadComboBoxItem runat="server" Text="Wire Transfer Rejected by Bank" 
            Value="28" />
        <telerik:RadComboBoxItem runat="server" Text="NSF Items Today" Value="10" />
        <telerik:RadComboBoxItem runat="server" Text="Wire Transfer Deleted by User" 
            Value="29" />
        <telerik:RadComboBoxItem runat="server" 
            Text="Online Transaction Processed" Value="11" />
        <telerik:RadComboBoxItem runat="server" Text="Wire Transfer Deleted by Bank" 
            Value="30" />
    </Items>
</telerik:RadComboBox>

代码背后:

Protected Sub OnItemChecked(ByVal sender As Object, ByVal e As RadComboBoxItemEventArgs)

    Select Case e.Item.Text
        Case "Check All"
            If e.Item.Checked = True Then
                For i = 0 To txtAlertType.Items.Count() - 1
                    txtAlertType.Items(i).Checked = True
                Next
            Else
                For i = 0 To txtAlertType.Items.Count() - 1
                    txtAlertType.Items(i).Checked = False
                Next
            End If

        Case "Custom Alerts"
            If e.Item.Checked = True Then
                For i = 0 To txtAlertType.Items.Count() - 1
                    If txtAlertType.Items(i).value < 14 And txtAlertType.Items(i).value > 0 Then
                        txtAlertType.Items(i).Checked = True
                    End If
                Next
            Else
                txtAlertType.Items(0).Checked = False
                For i = 0 To txtAlertType.Items.Count() - 1
                    If txtAlertType.Items(i).value < 14 And txtAlertType.Items(i).value > 0 Then
                        txtAlertType.Items(i).Checked = False
                    End If
                Next
            End If
        Case "Cash Management"
            If e.Item.Checked = True Then
                For i = 0 To txtAlertType.Items.Count() - 1
                    If txtAlertType.Items(i).value > 15 Then
                        txtAlertType.Items(i).Checked = True
                    End If
                Next
            Else
                txtAlertType.Items(0).Checked = False
                For i = 15 To txtAlertType.Items.Count() - 1
                    If txtAlertType.Items(i).value > 15 Then
                        txtAlertType.Items(i).Checked = True
                    End If
                Next
            End If
    End Select

End Sub

2 个答案:

答案 0 :(得分:0)

听起来你很适合新的Telerik RadTreeList。您还可以查看我的自定义控件RadComboTree

  

允许您的用户轻松浏览层次结构中的众多项目   使用RadDropDownTree for ASP.NET AJAX的数据列表。利用   各种数据绑定选项,使用二十个内置皮肤之一   或通过模板轻松自定义控件。请放心   该控件适用于任何浏览器和设备。

enter image description here

答案 1 :(得分:0)

这就是我最终做的事情:

<telerik:RadComboBox ID="txtAlertType" Runat="server" Visible="False" OnClientItemChecked="OnClientDropDown"
                    Width="205px" AutoPostBack="True" CheckBoxes="True"  DropDownCssClass="multipleRowsColumns"
                    EnableAutomaticLoadOnDemand="True" DropDownWidth="400px">

function OnClientDropDown(sender, eventArgs) {
    if (eventArgs.get_item().get_text() == "Custom Alerts") {
        var Combo = $find("<%=txtAlertType.ClientID %>");
        var items = Combo.get_items();
        var i = 2;
        if (items._array[i].get_checked()) {
            var combo = $find("<%= txtAlertType.ClientID %>");
            var comboItem = new Telerik.Web.UI.RadComboBoxItem();
            combo.trackChanges();
            combo.get_items().getItem(1).check();
            combo.get_items().getItem(3).check();
            combo.get_items().getItem(4).check();
            combo.get_items().getItem(6).check();
            combo.get_items().getItem(8).check();
            combo.get_items().getItem(10).check();
            combo.get_items().getItem(12).check();
            combo.get_items().getItem(14).check();
            combo.get_items().getItem(16).check();
            combo.get_items().getItem(18).check();
            combo.get_items().getItem(20).check();
            combo.get_items().getItem(22).check();
            combo.get_items().getItem(24).check();
            combo.commitChanges();
        } else {
           var combo = $find("<%= txtAlertType.ClientID %>");
            var comboItem = new Telerik.Web.UI.RadComboBoxItem();
            combo.trackChanges();
            combo.get_items().getItem(1).uncheck();
            combo.get_items().getItem(3).uncheck();
            combo.get_items().getItem(4).uncheck();
            combo.get_items().getItem(6).uncheck();
            combo.get_items().getItem(8).uncheck();
            combo.get_items().getItem(10).uncheck();
            combo.get_items().getItem(12).uncheck();
            combo.get_items().getItem(14).uncheck();
            combo.get_items().getItem(16).uncheck();
            combo.get_items().getItem(18).uncheck();
            combo.get_items().getItem(20).uncheck();
            combo.get_items().getItem(22).uncheck();
            combo.get_items().getItem(24).uncheck();
            combo.commitChanges();
        }
    }

    if (eventArgs.get_item().get_text() == "Cash Management") {
        var Combo = $find("<%=txtAlertType.ClientID %>");
        var items = Combo.get_items();
        var i = 5;
        if (items._array[i].get_checked()) {
            var combo = $find("<%= txtAlertType.ClientID %>");
            var comboItem = new Telerik.Web.UI.RadComboBoxItem();
            combo.trackChanges();
            combo.get_items().getItem(7).check();
            combo.get_items().getItem(9).check();
            combo.get_items().getItem(11).check();
            combo.get_items().getItem(13).check();
            combo.get_items().getItem(15).check();
            combo.get_items().getItem(17).check();
            combo.get_items().getItem(19).check();
            combo.get_items().getItem(21).check();
            combo.get_items().getItem(23).check();
            combo.get_items().getItem(25).check();
            combo.commitChanges();
        } else {
            var combo = $find("<%= txtAlertType.ClientID %>");
            var comboItem = new Telerik.Web.UI.RadComboBoxItem();
            combo.trackChanges();
            combo.get_items().getItem(7).uncheck();
            combo.get_items().getItem(9).uncheck();
            combo.get_items().getItem(11).uncheck();
            combo.get_items().getItem(13).uncheck();
            combo.get_items().getItem(15).uncheck();
            combo.get_items().getItem(17).uncheck();
            combo.get_items().getItem(19).uncheck();
            combo.get_items().getItem(21).uncheck();
            combo.get_items().getItem(23).uncheck();
            combo.get_items().getItem(25).uncheck();
            combo.commitChanges();
        }
    }

    if (eventArgs.get_item().get_text() == "Check All") {
        var Combo = $find("<%=txtAlertType.ClientID %>");
        var items = Combo.get_items();
        var i = 0;
        if (items._array[i].get_checked()) {
            var combo = $find("<%= txtAlertType.ClientID %>");
            var comboItem = new Telerik.Web.UI.RadComboBoxItem();
            combo.trackChanges();
            combo.get_items().getItem(1).check();
            combo.get_items().getItem(2).check();
            combo.get_items().getItem(3).check();
            combo.get_items().getItem(4).check();
            combo.get_items().getItem(6).check();
            combo.get_items().getItem(8).check();
            combo.get_items().getItem(10).check();
            combo.get_items().getItem(12).check();
            combo.get_items().getItem(14).check();
            combo.get_items().getItem(16).check();
            combo.get_items().getItem(18).check();
            combo.get_items().getItem(20).check();
            combo.get_items().getItem(22).check();
            combo.get_items().getItem(24).check();
            combo.get_items().getItem(5).check();
            combo.get_items().getItem(7).check();
            combo.get_items().getItem(9).check();
            combo.get_items().getItem(11).check();
            combo.get_items().getItem(13).check();
            combo.get_items().getItem(15).check();
            combo.get_items().getItem(17).check();
            combo.get_items().getItem(19).check();
            combo.get_items().getItem(21).check();
            combo.get_items().getItem(23).check();
            combo.get_items().getItem(25).check();
            combo.commitChanges();
        } else {
            var combo = $find("<%= txtAlertType.ClientID %>");
            var comboItem = new Telerik.Web.UI.RadComboBoxItem();
            combo.trackChanges();
            combo.get_items().getItem(1).uncheck();
            combo.get_items().getItem(2).uncheck();
            combo.get_items().getItem(3).uncheck();
            combo.get_items().getItem(4).uncheck();
            combo.get_items().getItem(6).uncheck();
            combo.get_items().getItem(8).uncheck();
            combo.get_items().getItem(10).uncheck();
            combo.get_items().getItem(12).uncheck();
            combo.get_items().getItem(14).uncheck();
            combo.get_items().getItem(16).uncheck();
            combo.get_items().getItem(18).uncheck();
            combo.get_items().getItem(20).uncheck();
            combo.get_items().getItem(22).uncheck();
            combo.get_items().getItem(24).uncheck();
            combo.get_items().getItem(5).uncheck();
            combo.get_items().getItem(7).uncheck();
            combo.get_items().getItem(9).uncheck();
            combo.get_items().getItem(11).uncheck();
            combo.get_items().getItem(13).uncheck();
            combo.get_items().getItem(15).uncheck();
            combo.get_items().getItem(17).uncheck();
            combo.get_items().getItem(19).uncheck();
            combo.get_items().getItem(21).uncheck();
            combo.get_items().getItem(23).uncheck();
            combo.get_items().getItem(25).uncheck();
            combo.commitChanges();
        }
    }
}