Dec 05, 2019, 9:56 AM
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
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);
}
}
}
}
Last edited by BillyChung; Dec 05, 2019 at 10:34 AM.
Reason: add using version