如何检查我的RadListBox中的所有项目

本文关键字:项目 RadListBox 我的 何检查 检查 | 更新日期: 2023-09-27 18:08:38

Aspx.cs:

RadListDirectionDetail.DataSource = m_listeDirection;    
RadListDirectionDetail.DataValueField = "DepartmentId";    
RadListDirectionDetail.DataTextField = "DepartmentName";    
RadListDirectionDetail.DataBind();    
if (RadListDirectionDetail.Items.Count > 0)    
{    
     for (int i = 0; i < RadListDirectionDetail.Items.Count; i++)    
     {    
          RadListDirectionDetail.Items[i].Checked = false;    
     }    
}

Aspx:

<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel2">    
    <telerik:RadListBox ID="RadListDirectionDetail" runat="server" CheckBoxes="true" Width="200px" ShowCheckAll = "true"     
     SelectionMode="Multiple" AutoPostBack="True" Height="55px" Skin="Outlook" Visible="false" Enabled="False">
    </telerik:RadListBox>    
</telerik:RadAjaxPanel>

如何检查我的RadListBox中的所有项目

我认为您的问题是RadListBox的Visible和Enabled属性都设置为False。

尝试

<telerik:RadListBox ID="RadListDirectionDetail" runat="server" CheckBoxes="true" Width="200px" ShowCheckAll = "true"     
 SelectionMode="Multiple" AutoPostBack="True" Height="55px" Skin="Outlook" Visible="True" Enabled="True">

RadListDirectionDetail.Items[i].Checked = true;   

您希望在页面加载时检查所有内容。您可以使用以下代码

代码在前

<telerik:RadListBox ID="RadListBox1" runat="server" CheckBoxes="true" SelectionMode="Multiple" OnItemDataBound="RadListBox1_ItemDataBound"></telerik:RadListBox>

背后的代码

protected void Page_Load(object sender, EventArgs e)
{
    // Check
    if (!IsPostBack)
    {
        // Variable
        DataTable dt = new DataTable();
        dt.Columns.Add("departmentID");
        dt.Columns.Add("departmentName");
        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("Dep1", "1");
        dic.Add("Dep2", "2");
        dic.Add("Dep3", "3");
        dic.Add("Dep4", "4");
        // Loop
        foreach (KeyValuePair<string, string> valuepair in dic) dt.Rows.Add(valuepair.Value, valuepair.Key);
        RadListBox1.DataSource = dt;
        RadListBox1.DataTextField = "departmentName";
        RadListBox1.DataValueField = "departmentID";
        RadListBox1.DataBind();

    }
}
protected void RadListBox1_ItemDataBound(object sender, RadListBoxItemEventArgs e)
{
    // Check Count
    if (RadListBox1.Items.Count > 0)
    {
        for (int i = 0; i < RadListBox1.Items.Count; i++)
            RadListBox1.Items[i].Checked = true;
    }
}

希望这将帮助您