Hello,
I’m trying to figure an issue with the RadComboBox (Ajax Q1 2014 version). I using Visual Studio 2012, Sql 2012 (the example code is using Adventure Works 2008 database), Web application with Master Content pages.
The combo boxes have CheckBoxes="true" EnablecheckAllItemsCheckBox="true" CheckedItemsTexts="DisplayAllInInput" set. My application needs multiple columns w/ multiple values filtering and to have initial values set on load.
In the included example there are 2 Combo Boxes. Initially Country has France and US Checked. Now uncheck both. Page refreshes. With no items checked. Open States combo box check ‘Ain’ first Item. Click the ‘Show’ button. The Id’s are shown as State Id 87. Now open the State combo box and uncheck the ‘Ain’ item. Now click off the combo box. Page refreshes. ‘Ain’ is still checked. The javascript event for OnClientDropDownClose is called which is supposed to raises the OnTextChanged event but dosen’t.
How do I get the Item to behave correctly??
David Carson
Ps. The code probably still has typos from the OCR processes.
<%@ Page Tit1e="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventwireup="true“
CodeBehind="Default.aspx.cs" Inherits:"webApplicationl._Default" %>
<%@ Register Assembly="Telerik.web.UI" Namespace="Telerik.web.UI" TagPrefix="telerik" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="Maincontent">
<telerik:RadScriptBlock ID="RadScriptBlockl" runat="server">
<script type="text/javascript">
function ApplyFilter(sender, args) {sender.raise_textChange(sender, args);}
</script>
</telerik:RadScriptBlock>
<telerik:RadComboBox ID="rcbo0" runat="server" DropDownAutowidth=“Enabled" AutoPostBack="true"
width="400px" CheckBoxes="true" EnablecheckAllItemsCheckBox="true"
CheckedItemsTexts="DisplayAllInInput" Label="Country:" DataTextField="Name"
DataValueField="CountryRegionCode" OnClientDropDownClosed="ApplyFilter" onTextChanged="CreateFilter0" />
<br />
<telerik:RadComboBox ID="rcbo1" runat="server" DropDownAutowidth="Enabled" AutoPostBack="true"
width="400px" CheckBoxes="true" EnablecheckAllItemsCheckBox="true"
CheckedItemsTexts="DisplayAllInInput“ Label="States:" DataTextField="Name"
DatavalueField="StateProvinceID" onClientDropDownClosed="ApplyFilter" OnTextChanged="CreateFilter1" />
<br />
<asp:Button ID="Button1" runat="server" Text="Show Sel Ids" OnClick="Buttonl_Click" />
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Rows="3"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label0“ runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
</asp:Content>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.web.UI;
using Telerik.web.UI;
namespace webApplication1
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//Session["Filter0"]
//Session["Filter1"] = "1,2,3,4,5,100,200,300";
Session["Filter0"] = "US,FR";
Session["Filter1"] = "";
}
protected override void OnPreRender(EventArgs e)
{
base.onPreRender(e);
Build_0_Data();
Build_1_Data();
Label0.Text = "Filter0 = " + Session["Filter0"];
Label1.Text = "Filterl = " + Session["Filter1"];
}
private static void SetChecked_Combo(object sender, object oSessionFilter)
{
if (oSessionFilter != null)
{
string sSessionFilter = oSessionFilter.ToString();
List<string> sValueArray = sSessionFilter.Split(new char[] {','}
, Stringsplitoptions.RemoveEmptyEntries).ToList<string>();
RadComboBoxItem comboltem;
RadComboBox combo = (RadComboBox)sender;
if (sValueArray.Count > 0)
{
foreach (string s in sValueArray)
{
comboItem = combo.Items.FindItemByValue(s);
if (comboItem != null)
comboItem.Checked = true;
}
}
}
}
public void CreateFilter0(object sender, EventArgs e)
{
CheckedCombo_CreateFilter(sender, "Filter0");
}
public void CreateFilter1(object sender, EventArgs e)
{
CheckedCombo_CreateFilter(sender, "Filter1");
}
private void CheckedCombo_CreateFilter(object sender, string sSessionName)
{
string sFilter = string.Empty;
if ((sender != null) && (sender.GetType() == typeof(RadComboBox)))
{
RadComboBox cbo = (RadComboBox)sender;
if ((cbo != null) && (cbo.CheckedItems != null))
{
foreach (RadComboBoxItem comboltem in cbo.CheckedItems)
{
if (!string.IsNullOrEmpty(sFilter))
sFilter += ",";
sFilter += comboItem.Value;
}
}
}
Session[sSessionName] = sFilter;
}
protected void Build_O_Data()
{
string sFilter = (string)Session[“Filter1"];
Sqlconnection sqlConn = new Sqlconnection(ConfigurationManager.
ConnectionStrings["Database1"].ConnectionString);
sqlConn.Open();
SqlCommand cmd_Tmp = new SqlCommand();
cmd_Tmp.Connection = sqlConn;
if (!string.IsNullOrEmpty(sFilter))
{
cmd_Tmp.CommandText = "DECLARE @x XML;"
+ "SET @x = '<i>' + REPLACE(@filter, ',', '</i><i>') + '</i>';"
+ "SELECT DISTINCT C.[CountryRegionCode],C.[Name]"
+ "FROM [Person].[CountryRegion] C"
+ "INNER JOIN [Person].[StateProvince] S"
+ "ON C.[CountryRegionCode] = S.[CountryRegionCode]"
+ "WHERE [StateProvinceID] IN (SELECT x.i.value('.', 'NVarChar(3)') From @x.nodes('//i') x(i))" ;
cmd_Tmp.Parameters.Add(new SqlParameter("@filter", sFilter));
}
else
cmd_Tmp.CommandText = "SELECT DISTINCT C.[CountryRegionCode],C.[Name] FROM [Person].[CountryRegion]C";
SqlDataAdapter sda = new SqlDataAdapter(cmd_Tmp);
DataTable dt = new DataTable("Tmp");
sda.Fill(dt);
rcbo0.DataSource = dt;
rcbo0.DataBind();
SetChecked_Combo(rcbo0, Session["Filter0"]);
}
protected void Build_1_Data()
{
string sFilter = (string)Session["Filter0"];
Sqlconnection sqlconn = new Sqlconnection(ConfigurationManager.
Connectionstrings["Database1"].Connectionstring);
sqlConn.Open();
Sqlcommand cmd_Tmp = new SqlCommand();
cmd_Tmp.Connection = sqlConn;
if (!string.IsNullOrEmpty(sFilter))
{
cmd_Tmp.CommandText = "DECLARE @x XML;“
+ "SET @x = '<i>' + REPLACE(@filter, ',', '</i><i>') + '</i>';"
+ "SELECT DISTINCT_S.[StateProvinceID],S.[Name]
+ "FROM [Person].[StateProvince] S"
+ "INNER JOIN [Person].[CountryRegion] C"
+ "ON C.[CountryRegionCode] = S.[CountryRegionCode]"
+ "WHERE S.[CountryRegionCode] IN (SELECT x.i.value('.', 'NVarChar(3)') From @x.nodes('//i') X(i))" ;
cmd_Tmp.Parameters.Add(new SqlParameter("@filter", sFilter));
}
else
cmd_Tmp.CommandText = "SELECT [StateProvinceID],[Name] FROM [Adventureworks2008].[Person].[StateProvince] ";
SqlDataAdapter sda = new SqlDataAdapter(cmd_Tmp);
DataTable dt = new DataTable("Tmp");
sda.Fill(dt);
rcbo1.DataSource = dt;
rcbo1.DataBind();
SetChecked_Combo(rcbo1, Session["Filter1"]);
}
protected void Button1_Click(object sender, EventArgs e)
{
string sFilter = string.Empty;
foreach (RadComboBoxItem comboItem in rcbo0.CheckedItems)
{
if (!string.IsNullorEmpty(sFilter))
sFilter += ",";
sFilter += comboItem.Value;
}
TextBox1.Text = "Sel Country ID: " + sFilter + System.Environment.NewLine;
sFilter = string.Empty;
foreach (RadComboBoxItem comboItem in rcbo1.CheckedItems)
{
if (!string.IsNullorEmpty(sFilter))
sFilter += ",";
sFilter += comboItem.Value;
}
TextBox1.Text += @"Sel State ID: " + sFilter;
}
}
}