RadComboBox w/ Chechboxes not unchecking first item

6 posts, 0 answers
  1. David
    David avatar
    3 posts
    Member since:
    Jun 2014

    Posted 26 Jun 2014 Link to this post

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

     

  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 01 Jul 2014 Link to this post

    Hi David,

    Please verify that your code in the SetChecked_Combo() method does not clear the checked items. You are calling it every time after the combo is populated with data.

    Attach sample project, so we can debug your code.

    Regards,
    Hristo Valyavicharski
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. David
    David avatar
    3 posts
    Member since:
    Jun 2014

    Posted 01 Jul 2014 in reply to Hristo Valyavicharski Link to this post

    Hello Hristo,

    The sample code is attached.

    Yes, it is because the comboboxes get re-bound due to other changes on the page and in the application. The combobox.CheckedItems get re-built from Session a variable that get read in on the OnTextChanged="CreateFilter1" event which then call the SetChecked_Combo()  w/ the correct string to set the checkboxes.

    What is happening is the combobox event 'OnClientDropownClosed' is being called and executed:

        <telerik:RadScriptBlock ID="RadScriptBlockl" runat="server">
            < script type="text/javascript">
                 function ApplyFilter(sender, args) { sender.raise_textChange(sender, args);}
            < /script>
        < /telerik:RadScriptBlock>

    This code in almost all circumstances invokes the TextChange server event.
    Except when there is one ( 1 ) item that is checked and it is the first item.

    How do I get the TextChange event to fire in this case using javvascipt ??

    David Carson
  5. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 04 Jul 2014 Link to this post

    Hi David,

    The code is attached and I have the AdventureWord2008 db, but as you said it has many typos after the OCR processing. I'm getting errors in the SQL queries. http://screencast.com/t/zqtmkAl5x0

    Please it again once again or just attach the cs file.

    Regards,
    Hristo Valyavicharski
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. David
    David avatar
    3 posts
    Member since:
    Jun 2014

    Posted 08 Jul 2014 in reply to Hristo Valyavicharski Link to this post

    I do not have access to Visual Studio or the ability to install software on this network.

    If you add a space on the end of each of the line with sql you will get it formatted correctly.

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

  7. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 11 Jul 2014 Link to this post

    Hi David,

    It looks like that there is some problem with your sql queries. I have copied the provided sql, but I received the following error: http://screencast.com/t/hOoJuIkj

    That's why I commented them and combo worked: http://screencast.com/t/PMieXGHr
    Please make sure that your is working correctly.

    Regards,
    Hristo Valyavicharski
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017