[CLOSED] Add checkbox to checkboxgroup during runtime

Page 5 of 5 FirstFirst ... 345
  1. #41
    Hi,

    I think this thread is appropriate for this new question.

    Well, if you will define Button with AjaxEvent in a user control you could use the following thing in AjaxEvent handler.
    this.Request["NewCheckbox1"]
    If this is null then NewCheckbox1 (it's id) is unchecked, if this is string ("NewCheckbox1 ") this checkbox is checked.

    Well, you could save list of checkboxes ids in Session when you render checkboxes.
  2. #42
    Hi Daniil,

    May be I am not understand your explaination, but here is what I'm trying to do. Let's take the example you provide. Once the checkboxes have been populated, the user make couple of selection changes, some were checked and now not checked. How do you iterate through the checkboxgroup to get the checkboxes names and theirs status (checked/unchecked)?

    Using your example, I tried to step through the code to find the Checkboxgroup with the id "Group1" and it does not exist. Since I'm not able to get a reference of the checkboxgroup, I'm not sure how I can get to the existing checkboxes. Any idea on how to do this?

    Thanks,
    Dan
  3. #43
    Hi,

    GroupCheckbox widget is created on client side and server knows nothing about this widget.

    So, don't try to get this control on server side.

    In according to the details that I provided a solution can look something like this.

    Example WindowEditor.ascx
    <%@ Control Language="C#" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <script runat="server">
        public static List<string> ids = new List<string>();
    
        [AjaxMethod]
        public void OpenWindow(int count)
        {
            string[] checkboxIds = new string[count];
            bool[] checkeds = new bool[count];
            ids.Clear();
            for (int i = 0; i < count; i++)
            {
                var id = "NewCheckbox" + (i + 1);
                checkboxIds[i] = id;
                checkeds[i] = (i % 2) == 0;
                ids.Add(id);
            }
            string jsonCheckboxIds = JSON.Serialize(checkboxIds);
            string jsonCheckeds = JSON.Serialize(checkeds);
            ScriptManager.GetInstance(this.Context).AddScript("openDetailsWindow({0}, {1})", jsonCheckboxIds, jsonCheckeds);
        }
    
        protected void TestHandler(object sender, AjaxEventArgs e)
        {
            bool[] checkeds = new bool[ids.Count];
            int i = 0;
            foreach (var id in ids)
            {
                checkeds[i++] = !String.IsNullOrEmpty(this.Request[id]);
            }
    
            string result = "";
            foreach (var c in checkeds)
            {
                result += c + " ";
            }
            Ext.Msg.Alert("AjaxEvent", result).Show();
        }
    </script>
    
    <script type="text/javascript">
        var openDetailsWindow = function(checkboxIds, checkeds) {
            var cfg = {
                id: "Group1",
                renderTo: TabGroup.body,
                itemCls: "x-form-cb-label-nowrap",
                items: [],
                columns: 1
            };
            for (var i = 0; i < checkboxIds.length; i++) {
                var id = checkboxIds[i],
                    checked = checkeds[i];
                cfg.items.push({
                    id: id,
                    xtype: "checkbox",
                    inputValue: id,
                    boxLabel: id,
                    checked: checked
                });
            }
            var group = Ext.getCmp("Group1");
            if (group) {
                group.destroy();
            }
    
            WindowEditor1_Window1.show();
            new Ext.form.CheckboxGroup(cfg);
    
        }
    </script>
    
    <ext:Window ID="Window1" runat="server" Title="Details" Width="400" Height="400"
        ShowOnLoad="false">
        <Body>
            <ext:FitLayout runat="server">
                <ext:TabPanel runat="server" DeferredRender="false">
                    <Tabs>
                        <ext:Tab runat="server" Title="Some title" Html="Some content" />
                        <ext:Tab 
                            ID="TabGroup" 
                            runat="server" 
                            Title="CheckboxGroup" 
                            IDMode="Explicit">
                            <Body>
                                <ext:Button runat="server" Text="Get checkboxes">
                                    <AjaxEvents>
                                        <Click OnEvent="TestHandler" />
                                    </AjaxEvents>
                                </ext:Button>
                            </Body>
                        </ext:Tab>
                    </Tabs>
                </ext:TabPanel>
            </ext:FitLayout>
        </Body>
    </ext:Window>
  4. #44
    Hi Daniil,

    My apology for the confusion. I don't mean to get the name and status of the checkboxes during the creation of them. I need to find a way to get to these checkboxes after they have already populated and the user made changes to them. For instance, in your example, 3 checkboxes was created and 2 of them set checked to true. If I uncheck all of them and then select the update button, i'd like to be able to get a hold of these checkboxes so i can update them properly. I hope this will clear things up.

    thanks,
    Dan
  5. #45
    Daniil,

    One more thing. I think I can get a hold of the checkboxgroup on the client side using the following

    function getCheckboxgroup(){
            var group = Ext.getCmp("Group1");
            return group;
        }
    However, the problem that I'm facing is the getting the list of checkboxes and theirs names and status so i can update them in the database (preferrably on the server side code) after the user is done with making changes to the checkboxes.

    thanks,
    Dan
    Last edited by Daniil; Jan 12, 2011 at 10:10 PM. Reason: Please use [CODE] tags
  6. #46
    Please clarify did you try WindowsEditor.ascx that I posted?

    It appears to suit the requirements that you described.
  7. #47
    Daniil,

    You're correct! I think I'm doing too many things at the same time and didn't see the added example. My fault. You've saved the day once again!

    Thanks,
    Daniel
Page 5 of 5 FirstFirst ... 345

Similar Threads

  1. [CLOSED] Checkboxgroup not retaining checkbox items
    By Edward in forum 1.x Legacy Premium Help
    Replies: 13
    Last Post: Apr 21, 2015, 12:23 PM
  2. Replies: 7
    Last Post: Feb 13, 2012, 2:25 PM
  3. Replies: 2
    Last Post: Jan 12, 2012, 1:33 PM
  4. Runtime Checkbox value update issue.
    By ajviradia in forum 1.x Help
    Replies: 1
    Last Post: Apr 08, 2011, 5:23 PM
  5. [CLOSED] CheckBoxGroup DataIndex for each child checkbox
    By webclouder in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: May 11, 2010, 4:22 PM

Posting Permissions