Help! Set the value in the direct method of checkbox after dynamic create checkboxgroup.

  1. #1

    Help! Set the value in the direct method of checkbox after dynamic create checkboxgroup.

    I have create the checkbox of the checkboxgroup in the event Page_Init().
    But I dont know how to set the checked value of the checkbox after I set the checkboxgroup's name value in the direct method.
    My code is below.Pls help me.Many thanks.
     protected void Page_Init(object sender, EventArgs e)
        {
            ShowAuthorityList();
        }
    
    ///add checkbox item to the CheckboxGroup in the panel.
     protected void ShowAuthorityList()
        {
            var bb = Logistrics.DataAccess.AuthorityDir.Query(" ").OrderBy(x => x.AuthorityOrder);
            List<AuthorityDir> ld = bb.ToList<AuthorityDir>();
            int i = 0;
            foreach (CheckboxGroup cbg in pnl.Items)
            {
                foreach (AuthorityDir ad in ld)
                {
                    ++i;
                    Ext.Net.Checkbox cb = new Ext.Net.Checkbox();
                    cb.BoxLabel = ad.AuthorityName;
                    cb.ID = ad.AuthorityID + ad.AuthorityTag + i.ToString();
                    cb.EnableViewState = false;
                    cb.Checked = false;
                    cb.Name = ad.AuthorityTag + "," + ad.AuthorityID;
                    cbg.Items.Add(cb);
                }
                cbg.Hidden = true;
            }
        }
    
    ///change the CheckboxGroup's name value in the combobox's select event.
    protected void ShowAuthority(object sender, DirectEventArgs e)
        {
            if (cb_Menu.SelectedIndex >= 0)
            {
                var aa = Logistrics.DataAccess.Module.Query(" where ModuleTypeID ='" + cb_Menu.SelectedItem.Value + "'").OrderBy(x => x.ModuleOrder);
                List<Module> lm = aa.ToList<Module>();
                foreach (CheckboxGroup cbg in pnl.Items)
                {
                    foreach (Module model in lm)
                    {
    
                        if (cbg.ID.Contains(model.ModuleTag))
                        {
                            cbg.FieldLabel = model.ModuleName;
                            cbg.Name = model.ModuleID;
                            cbg.EnableViewState = true;
                            cbg.Hidden = false;
                        }
                    }
                   //SetAuthorityList();
                }
    
            }
        }
    
    
        ///set the value of the checkbox of the CheckboxGroup in the panel
        protected void SetAuthorityList()
        {
    
            if (cb_Role.SelectedIndex >= 0)
            {
                foreach (CheckboxGroup cbg in pnl.Items)
                {
                    var bb = Logistrics.DataAccess.RoleAuthorityList.Query(" where RoleID='" + cb_Role.SelectedItem.Value + "' and ModuleID='" + cbg.Name + "'");
                    List<RoleAuthorityList> lr = bb.ToList<RoleAuthorityList>();
                    foreach (RoleAuthorityList ra in lr)
                    {
                        foreach (Checkbox cb in cbg.Items)
                        {
                            if (cb.Name.Contains(ra.AuthorityTag))
                            {
                                cb.Checked = true;
                            }
                        }
                    }
                }
    
            }
     
        }
    
    ///the aspx file code 
    
    <ext:ComboBox 
                                ID="cb_Menu" 
                                runat="server" 
                                StoreID="Store2"
                                FieldLabel="Menu"
                                Editable="false"
                                AllowBlank="true" 
                                DisplayField="ModuleTypeName" 
                                ValueField="ModuleTypeID" 
                                TypeAhead="true"
                                Mode="Local" 
                                ForceSelection="true" 
                                TriggerAction="All" 
                                EmptyText="select one choice..."
                                Width="250" 
                                >
                                        <DirectEvents>
                                        
            <Select  OnEvent="ShowAuthority"  Failure="Ext.MessageBox.alert('Load failed', 'Error during ajax event!');"/>
            </DirectEvents>
  2. #2
    Hi,

    Please see the example how to add a checkbox to CheckboxGroup during DirectEvent.
    http://forums.ext.net/showthread.php...ll=1#post33722
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    Please see the example how to add a checkbox to CheckboxGroup during DirectEvent.
    http://forums.ext.net/showthread.php...ll=1#post33722
    I have seen that example, but my situation is not like that.
    I have added some checkboxes to CheckboxGroup in the Page_Init event. When I select one option in the combobox, there is a direct method will chage the CheckboxGroup's Name value. And after the CheckboxGroup's Name value has been changed,I want to set the checked of the checkbox in the CheckboxGroup.
  4. #4
    Well, CheckboxGroup doesn't use its Name property. So, I'm not sure why you need to change it.

    Though even if I'm trying to follow your scenario I can't see a problem to set up Checked for some Checkbox within CheckboxGroup after changing its Name.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Test(object sender, DirectEventArgs e)
        {
            this.CheckboxGroup1.Name = "New_Name";
            this.Checkbox2.Checked = true;
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:CheckboxGroup ID="CheckboxGroup1" runat="server" ColumnsNumber="1">
                <Items>
                    <ext:Checkbox ID="Checkbox1" runat="server" />
                    <ext:Checkbox ID="Checkbox2" runat="server" />
                </Items>
            </ext:CheckboxGroup>
            <ext:Button 
                runat="server" 
                Text="Change Name and set up checked item" 
                OnDirectClick="Test" />
        </form>
    </body>
    </html>
  5. #5
    Quote Originally Posted by Daniil View Post
    Well, CheckboxGroup doesn't use its Name property. So, I'm not sure why you need to change it.

    Though even if I'm trying to follow your scenario I can't see a problem to set up Checked for some Checkbox within CheckboxGroup after changing its Name.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Test(object sender, DirectEventArgs e)
        {
            this.CheckboxGroup1.Name = "New_Name";
            this.Checkbox2.Checked = true;
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:CheckboxGroup ID="CheckboxGroup1" runat="server" ColumnsNumber="1">
                <Items>
                    <ext:Checkbox ID="Checkbox1" runat="server" />
                    <ext:Checkbox ID="Checkbox2" runat="server" />
                </Items>
            </ext:CheckboxGroup>
            <ext:Button 
                runat="server" 
                Text="Change Name and set up checked item" 
                OnDirectClick="Test" />
        </form>
    </body>
    </html>

    your example is very good.But your CheckboxGroup's Item was not dynamic created.And I maked a mistake in the last reply, I was chage the CheckboxGroup's FieldLabel.After change the FieldLabel, I set the checked value of the checkbox dynamic created, The CheckboxGroup will display nothing.
  6. #6
    There should not be any difference when the things are defined in markup or Page_Init.

    Could you provide a full runnable sample to reproduce the problem?
  7. #7
    Quote Originally Posted by Daniil View Post
    There should not be any difference when the things are defined in markup or Page_Init.

    Could you provide a full runnable sample to reproduce the problem?
    Here is my full page code.
    the aspx file:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="RoleAuthority.aspx.cs" Inherits="Admin_Permission_RoleAuthority" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server"/>
    
    <ext:Store runat="server" ID="GroupStore">
        <Reader>
            <ext:JsonReader IDProperty="GroupID">
                <Fields>
                    <ext:RecordField Name="GroupID" />
                    <ext:RecordField Name="GroupName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    
    
    
    <ext:Store runat="server" ID="Store3" OnRefreshData="Store3_RefreshData">
        <Reader>
            <ext:JsonReader IDProperty="RoleID">
                <Fields>
                    <ext:RecordField Name="RoleID" />
                    <ext:RecordField Name="RoleName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    
    <ext:Store runat="server" ID="Store2">
        <Reader>
            <ext:JsonReader IDProperty="ModuleTypeID">
                <Fields>
                    <ext:RecordField Name="ModuleTypeID" />
                    <ext:RecordField Name="ModuleTypeName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Window 
        ID="EmployeeDetailsWindow" 
        runat="server" 
        Icon="Group" 
        Title="角色权限"
        Width="600" 
        Height="600" 
        Modal="true"
        Closable="false" 
        Layout="Fit">
        <Items>
    <ext:Panel 
                        ID="RoleAuthorityInfoTab" 
                        runat="server" 
                        Title="权限信息" 
                        Icon="ChartOrganisation"
                        Padding="5"
                        Layout="Form">
                        <Items>
                        <ext:ComboBox 
                                ID="cb_Group" 
                                runat="server" 
                                StoreID="GroupStore" 
                                FieldLabel="所属用户组"
                                 Editable="false"
                                AllowBlank="true" 
                                DisplayField="GroupName" 
                                ValueField="GroupID" 
                                TypeAhead="true"
                                Mode="Local" 
                                ForceSelection="true" 
                                TriggerAction="All" 
                                EmptyText="选择一个用户组..."
                                Width="250" 
                                 >
                                         <Listeners>
                <Select Handler="#{Store3}.reload();" />
            </Listeners>  
    
    
                                 </ext:ComboBox>
    
                                  <ext:ComboBox 
                                ID="cb_Role" 
                                runat="server" 
                                StoreID="Store3" 
                                FieldLabel="角 色"
                                 Editable="false"
                                AllowBlank="true" 
                                DisplayField="RoleName" 
                                ValueField="RoleID" 
                                TypeAhead="true"
                                Mode="Local" 
                                ForceSelection="true" 
                                TriggerAction="All" 
                                EmptyText="选择一个角色..."
                                Width="250" 
                                 >
    <%--                             <Listeners>
                                 <Select Handler="Ext.net.DirectMethods.ShowAuthority();" />
                                 </Listeners>--%>
                                        <DirectEvents>
                                        
            <Select  OnEvent="ShowAuthority"  Failure="Ext.MessageBox.alert('Load failed', 'Error during ajax event!');"/>
            </DirectEvents>
    
    
                                 </ext:ComboBox>
    
                            <ext:ComboBox 
                                ID="cb_Menu" 
                                runat="server" 
                                StoreID="Store2"
                                FieldLabel="父菜单"
                                Editable="false"
                                AllowBlank="true" 
                                DisplayField="ModuleTypeName" 
                                ValueField="ModuleTypeID" 
                                TypeAhead="true"
                                Mode="Local" 
                                ForceSelection="true" 
                                TriggerAction="All" 
                                EmptyText="选择一个父菜单..."
                                Width="250" 
                                >
    <%--                            <Listeners>
                                 <Select Handler="Ext.net.DirectMethods.ShowAuthority();" />
                                 </Listeners>--%>
                                        <DirectEvents>
                                        
            <Select  OnEvent="ShowAuthority"  Failure="Ext.MessageBox.alert('Load failed', 'Error during ajax event!');"/>
            </DirectEvents>
                                </ext:ComboBox>
                     <ext:Panel ID="pnl" runat="server" Layout="FormLayout" >
                     <Items>
                     <ext:CheckboxGroup ID="cbg_AuthorityPage" runat="server" ColumnsNumber="4" FieldLabel="123" LazyMode="Instance"></ext:CheckboxGroup>
                     <ext:CheckboxGroup ID="cbg_GroupPage" runat="server" ColumnsNumber="4" FieldLabel="123" LazyMode="Instance"></ext:CheckboxGroup>
                     <ext:CheckboxGroup ID="cbg_ModulesPage" runat="server" ColumnsNumber="4" FieldLabel="123" LazyMode="Instance"></ext:CheckboxGroup>
                     <ext:CheckboxGroup ID="cbg_RoleAuthorityPage" runat="server" ColumnsNumber="4" FieldLabel="123" LazyMode="Instance"></ext:CheckboxGroup>
                     <ext:CheckboxGroup ID="cbg_RolesPage" runat="server" ColumnsNumber="4" FieldLabel="123" LazyMode="Instance"></ext:CheckboxGroup>
                     </Items>
                    </ext:Panel>
                        </Items>
                    </ext:Panel>
                   
        </Items>
        <Buttons>
            <ext:Button ID="Button1" runat="server" Text="保 存" Icon="Disk" 
            >
            <Listeners>
                    <Click Handler="CompanyX.SaveAuthority();" />
                </Listeners>
            </ext:Button>
        </Buttons>
    </ext:Window>
        </form>
    </body>
    </html>
    the cs file:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    using Logistrics.DataAccess;
    public partial class Admin_Permission_RoleAuthority : System.Web.UI.Page
    {
    
        protected void Page_Init(object sender, EventArgs e)
        {
            ShowAuthorityList();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
    
            if (!X.IsAjaxRequest)
            {
                BindGroup();
                BindMenuType();
    
            }
        }
    
    
        protected void BindGroup()
        {
    
                var aa = Logistrics.DataAccess.Group.Query("").OrderBy(x => x.GroupOrder);
                this.GroupStore.DataSource = aa;
                this.GroupStore.DataBind();
    
        }
    
    
        protected void BindMenuType()
        {
    
            var aa = Logistrics.DataAccess.ModuleType.Query("").OrderBy(x => x.ModuleTypeOrder);
            this.Store2.DataSource = aa;
            this.Store2.DataBind();
    
        }
    
        protected void BindRole()
        {
            if (cb_Group.SelectedIndex >= 0)
            {
                var aa = Logistrics.DataAccess.Role.Query(" where RoleGroupID ='" + cb_Group.SelectedItem.Value + "'").OrderBy(x => x.RoleOrder);
                this.Store3.DataSource = aa;
                this.Store3.DataBind();
            }
        }
    
    
        protected void ShowAuthorityList()
        {
            var bb = Logistrics.DataAccess.AuthorityDir.Query(" ").OrderBy(x => x.AuthorityOrder);
            List<AuthorityDir> ld = bb.ToList<AuthorityDir>();
            int i = 0;
            foreach (CheckboxGroup cbg in pnl.Items)
            {
                foreach (AuthorityDir ad in ld)
                {
                    ++i;
                    Ext.Net.Checkbox cb = new Ext.Net.Checkbox();
                    cb.BoxLabel = ad.AuthorityName;
                    cb.ID = ad.AuthorityID + ad.AuthorityTag + i.ToString();
                    cb.EnableViewState = false;
                    cb.Checked = false;
                    cb.DataIndex = ad.AuthorityTag + "," + ad.AuthorityID;
                    cbg.Items.Add(cb);
                }
                //cbg.Hidden = true;
            }
        }
    
        protected void ShowAuthority(object sender, DirectEventArgs e)
        {
            if (cb_Menu.SelectedIndex >= 0)
            {
                var aa = Logistrics.DataAccess.Module.Query(" where ModuleTypeID ='" + cb_Menu.SelectedItem.Value + "'").OrderBy(x => x.ModuleOrder);
                List<Module> lm = aa.ToList<Module>();
                foreach (CheckboxGroup cbg in pnl.Items)
                {
                    foreach (Module model in lm)
                    {
    
                        if (cbg.ID.Contains(model.ModuleTag))
                        {
                            cbg.FieldLabel = model.ModuleName;
                            cbg.DataIndex = model.ModuleID;
                            cbg.EnableViewState = true;
                            cbg.Hidden = false;
                        }
                    }
                   //SetAuthorityList();
                }
                pnl.Render();
                pnl.DoLayout();
            }
        }
    
    
        protected void SetAuthorityList()
        {
    
            if (cb_Role.SelectedIndex >= 0)
            {
                foreach (CheckboxGroup cbg in pnl.Items)
                {
                    var bb = Logistrics.DataAccess.RoleAuthorityList.Query(" where RoleID='" + cb_Role.SelectedItem.Value + "' and ModuleID='" + cbg.DataIndex + "'");
                    List<RoleAuthorityList> lr = bb.ToList<RoleAuthorityList>();
                    foreach (RoleAuthorityList ra in lr)
                    {
                        foreach (Checkbox cb in cbg.Items)
                        {
                            if (cb.DataIndex.Contains(ra.AuthorityTag))
                            {
                                cb.Checked = true;
                            }
                        }
                    }
                    //pnl.Show();
                    //pnl.Render();
                    //pnl.DoLayout();
                }
    
            }
     
        }
    
        protected void ListAuthority(object sender, DirectEventArgs e)
        {
            //string id = e.ExtraParams["id"];
            foreach (Component c in pnl.Items)
            {
                if (c.GetType() == typeof(CheckboxGroup))
                {
                    
                }
            }
            //var bb = Logistrics.DataAccess.RoleAuthorityList.Query(" where RoleID='"+id+"'");
    
           
        }
    
        protected void Store3_RefreshData(object sender, Ext.Net.StoreRefreshDataEventArgs e)
        {
            var aa = Role.Query(" where RoleGroupID ='" + cb_Group.SelectedItem.Value + "'").OrderBy(x => x.RoleOrder);
            this.Store3.DataSource = aa;
            e.Total = aa.Count();
            this.Store3.DataBind();
    
        }
    
        [DirectMethod(Namespace = "CompanyX")]
        //protected void SaveAuthority(object sender, DirectEventArgs e)
        public void SaveAuthority()
        {
           
        }
  8. #8
    I'm getting
    Compiler Error Message: CS0103: The name 'Logistrics' does not exist in the current context
    Could you provide a runnable and simplified sample like this one?
    http://forums.ext.net/showthread.php...ll=1#post74085

Similar Threads

  1. [CLOSED] Access Direct Method in Dynamic Usercontrol
    By SymSure in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Jun 11, 2013, 11:35 AM
  2. [CLOSED] Output Cache issue with Direct Method / Direct Event
    By amitpareek in forum 1.x Legacy Premium Help
    Replies: 18
    Last Post: Mar 01, 2013, 5:03 AM
  3. Replies: 2
    Last Post: Jan 12, 2012, 1:33 PM
  4. Direct method and direct event over SSL?
    By dimitar in forum 1.x Help
    Replies: 0
    Last Post: Oct 08, 2011, 8:09 PM
  5. [CLOSED] Add checkbox to checkboxgroup during runtime
    By dnguyen in forum 1.x Legacy Premium Help
    Replies: 46
    Last Post: Jan 12, 2011, 10:15 PM

Posting Permissions