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

时间:2015-08-19 13:54:46

标签: c# asp.net telerik

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>

2 个答案:

答案 0 :(得分:0)

我认为您的问题是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;   

答案 1 :(得分:0)

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

前面的代码

<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;
    }
}

希望这会对你有所帮助