0

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

谢谢,

迪伦·帕特尔

4

1 回答 1

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

于 2017-04-10T09:00:06.243 回答