initial state of CheckBoxGroup when update content

  1. #1

    initial state of CheckBoxGroup when update content

    Hi All,

    I have a ComboBox and CheckBoxGroup.
    I want to change items of CheckBoxGroup when selecting ComboBox items.

    Now there's a problem. What I checked at CheckBoxGroup will remain their state after changing the ComboBox selection and the content of CheckBoxGroup has changed.How could I make the CheckBoxGroup be initial state?

    Here is my code.
    ext.net 1.2.0
    vs 2012

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DynamicCheckBoxGroup.aspx.cs" Inherits="Ext.DynamicCheckBoxGroup" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <ext:ResourceManager ID="panelResourceManager" DirectMethodNamespace="ExtRM" Locale="utf-8" runat="server"></ext:ResourceManager>
        <form id="form1" runat="server">
            <div>
                <ext:Viewport ID="tabContentViewport" runat="server" Layout="FitLayout" HideBorders="true">
                    <Items>
                        <ext:Container ID="tabContainer" runat="server" Region="Center" Title="">
                            <Items>
                                <ext:BorderLayout ID="tabContentBorderLayout" runat="server">
                                    <North></North>
                                    <West></West>
                                    <Center>
                                        <ext:Panel ID="BannerPanel" runat="server" Border="false" HideBorders="true" Collapsed="false"
                                            Collapsible="false" Height="108">
                                            <Content>
                                                <ext:ComboBox ID="cbDemo" runat="server">
                                                    <DirectEvents>
                                                        <Select ViewStateMode="Enabled" OnEvent="CbChange_Event">
                                                            <EventMask ShowMask="true" MinDelay="250" Target="Page" />
                                                        </Select>
                                                    </DirectEvents>
                                                </ext:ComboBox>
                                                <ext:CheckboxGroup ID="checkBoxGroupDynamicDemo" runat="server">
                                                </ext:CheckboxGroup>
                                            </Content>
                                        </ext:Panel>
                                    </Center>
                                    <South></South>
                                </ext:BorderLayout>
                            </Items>
                        </ext:Container>
                    </Items>
                </ext:Viewport>
            </div>
        </form>
    </body>
    </html>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    using Ext.Net;
    
    namespace Ext
    {
        public partial class DynamicCheckBoxGroup : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                initCombox();
                initCheckBoxGroupDemo(cbDemo.SelectedItem.Value);
            }
    
            protected void CbChange_Event(object sender, DirectEventArgs args)
            {
                checkBoxGroupDynamicDemo.Reset();
                BannerPanel.UpdateContent();
            }
    
            private void initCombox()
            {
                IList<Ext.Net.ListItem> listItems = new List<Ext.Net.ListItem>();
                listItems.Add(new Ext.Net.ListItem("TextA", "ValueA"));
                listItems.Add(new Ext.Net.ListItem("TextB", "ValueB"));
                listItems.Add(new Ext.Net.ListItem("TextC", "ValueC"));
    
                foreach (Ext.Net.ListItem item in listItems)
                {
                    cbDemo.Items.Add(item);
                }
    
            }
    
            private void initCheckBoxGroupDemo(string comboBoxVal = null)
            {
                checkBoxGroupDynamicDemo.Clear();
    
                checkBoxGroupDynamicDemo.Vertical = true;
                checkBoxGroupDynamicDemo.ColumnsNumber = 1;
    
                IList<Checkbox> checkboxItems = new List<Checkbox>();
    
                if (string.IsNullOrEmpty(comboBoxVal) || comboBoxVal == "ValueA")
                {
                    checkboxItems.Add(new Checkbox(false, "CheckA1"));
                    checkboxItems.Add(new Checkbox(false, "CheckA2"));
                    checkboxItems.Add(new Checkbox(false, "CheckA3"));
                }
                else if (comboBoxVal == "ValueB")
                {
                    checkboxItems.Add(new Checkbox(false, "CheckB1"));
                    checkboxItems.Add(new Checkbox(false, "CheckB2"));
                    checkboxItems.Add(new Checkbox(false, "CheckB3"));
                }
                else if (comboBoxVal == "ValueC")
                {
                    checkboxItems.Add(new Checkbox(false, "CheckC1"));
                    checkboxItems.Add(new Checkbox(false, "CheckC2"));
                    checkboxItems.Add(new Checkbox(false, "CheckC3"));
                }
    
                foreach (Checkbox item in checkboxItems)
                {
                    checkBoxGroupDynamicDemo.Items.Add(item);
                }
            }
        }
    }
    Attached Thumbnails Click image for larger version. 

Name:	before(choose A and checked).jpg 
Views:	11 
Size:	13.0 KB 
ID:	25298   Click image for larger version. 

Name:	after(just choose B).jpg 
Views:	9 
Size:	13.1 KB 
ID:	25299  
    Last edited by BillyChung; Dec 05, 2019 at 10:34 AM. Reason: add using version

Similar Threads

  1. [CLOSED] CheckBoxGroup initial state
    By cwolcott in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 06, 2012, 6:20 AM
  2. [CLOSED] Reset GridPanel columns to initial state
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: Jul 18, 2011, 5:21 PM
  3. Accordion Layout initial state
    By dcrysler in forum 1.x Help
    Replies: 1
    Last Post: Jul 15, 2011, 8:53 PM
  4. Replies: 0
    Last Post: Oct 19, 2010, 7:39 AM
  5. How to maintain state of Checkboxgroup
    By Jamishra in forum 1.x Help
    Replies: 0
    Last Post: Nov 19, 2009, 12:01 PM

Tags for this Thread

Posting Permissions