CheckedItems.Count始终返回零值(0)

时间:2017-04-10 06:38:50

标签: asp.net telerik telerik-ajax

我使用telerik:radcombobox有多个选择值。我有绑定数据LoadOndemand.All工作正常但是当我点击提交按钮然后CheckedItems.Count = 0。

谢谢,

Dhiren Patel

1 个答案:

答案 0 :(得分:1)

我相信您正在使用RadComboBox的EnableLoadOnDemand属性。在按需加载时,服务器端无法访问RadComboBox项,因此始终返回CheckedItems以及SelectedItems计为零,这是一个已知问题。这是因为使用ItemsRequested事件处理程序或WebService按需加载的RadComboBox项目在服务器上不存在,并且无法使用服务器端FindItemByText / Value方法进行访问。 SelectedItem和SelectedIndex属性始终为Null / Nothing。这是速度所需要的(否则如果状态信息和ViewState被持久化,组合框将不会对每个按键响应)。

请在不使用按需加载的情况下查看以下代码,这在我的最后工作正常。

<telerik:RadComboBox runat="server" ID="RadComboBox1" CheckBoxes="true">
</telerik:RadComboBox>
<br />
<br />
<telerik:RadButton ID="RadButton1" runat="server" Text="Get Count" OnClick="RadButton1_Click">
</telerik:RadButton>

代码背后:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
    populateRadCombobox("select ContactName from Customers");
}
}
protected void populateRadCombobox(string query)
{
String ConnString =
ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(ConnString);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(query, conn);

DataTable myDataTable = new DataTable();

conn.Open();
try
{
    adapter.Fill(myDataTable);
    RadComboBox1.DataTextField = "ContactName";
    RadComboBox1.DataSource = myDataTable;
    RadComboBox1.DataBind();
}
finally
{
    conn.Close();
}
}
protected void RadButton1_Click(object sender, EventArgs e)
{
if (RadComboBox1.CheckedItems.Count > 0)
{
    //business logic goes here
}
else
{

}

参考: http://www.telerik.com/forums/checkeditems-count-always-returns-a-value-of-zero-0

http://www.telerik.com/forums/radcombobox-losing-client-selections-on-postback

相关问题