【问题标题】:add checkbox in dropdownlist在下拉列表中添加复选框
【发布时间】:2014-03-05 04:05:26
【问题描述】:

我在我的项目中使用 Telerik 控制。 我想在 drdownlist 中添加复选框并选择多个值并存储在数据库中。 我正在使用 c#.net 语言。它是基于窗口的应用程序。

【问题讨论】:

    标签: c# sql .net winforms telerik


    【解决方案1】:

    如果您使用的是 Windows 应用程序,那么最好使用“RadListBoxItem”而不是下拉列表。在 Telerik 中易于使用且使用效率更高。

     for (int i = 0; i < 10; ++i)
            {
                RadListBoxItem item = new RadListBoxItem();
                RadCheckBoxElement checkBox = new RadCheckBoxElement();
                checkBox.Text = "Item " + i;
                checkBox.ToggleState = i % 2 == 0 ? Telerik.WinControls.Enumerations.ToggleState.On: Telerik.WinControls.Enumerations.ToggleState.Off;
                //remove this line if you dont want to close popup on checkbox checked
                checkBox.ToggleStateChanged += new StateChangedEventHandler(checkBox_ToggleStateChanged);
                item.Children.Add(checkBox);
    
                this.radComboBox1.Items.Add(item);
            }
    

    在加载表单或您自己想要的位置编写上述代码。然后写下面的代码

     void checkBox_ToggleStateChanged(object sender, StateChangedEventArgs args)
        {
            this.radComboBox1.CloseDropDown();
        }
    

    使用的命名空间是using Telerik.WinControls.UI;

    【讨论】:

    • 您也可以查看此链接,telerik.com/support/code-library/radmultiselectdropdownlist ..它将允许在 DROPDOWNLIST 中进行多选。
    • @snehal 如果以上任何答案对您有帮助,请单击每个答案前显示的勾号将其标记为答案。
    • 在此代码中如何获取选定的值。b'coz in radcombobox 无法显示选中的项目。
    【解决方案2】:

    您可以使用您正在使用的控件的ItemTemplate 属性并在其中插入Checkbox。那么剩下的只是一个绑定问题。

    假设您使用的是RadComboBox,它看起来像..

        <telerik:RadComboBox ItemsSource="{Binding YourCollectionOfProperties}">
            <telerik:RadComboBox.ItemTemplate>
                <DataTemplate>
                    <CheckBox Content="{Binding YourPropertyDescription}" IsChecked="{Binding IsPropertySelected}"/>
                </DataTemplate>
            </telerik:RadComboBox.ItemTemplate>
        </telerik:RadComboBox>
    

    【讨论】:

    • 但我在窗口基础应用程序中工作,此代码在 asp.net 中。
    • 在 RadCombobox 中设置 CheckBoxes="true"
    • 哦..我的错..你可能想看看这里然后dotnetgallery.com/kb/…
    猜你喜欢
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-26
    • 2020-12-18
    • 2010-10-16
    相关资源
    最近更新 更多