Gridpanel SelectedRows - dynamic usercontrol

  1. #1

    Gridpanel SelectedRows - dynamic usercontrol

    Hi Everyone,

    I'm trying to get the SelectedRows form a dynamic loaded usercontrol that contains a gridpanel. Everytime i hit the count the result is 0, while i've selected several items. Can anyone help me? Is there a better way to do this? Should i create every control in codebehind instead of using a usercontrol? Here is my example:

    usercontrol that contains the gridpanel
    <ext:Label ID="LabelTitel" runat="server" Height="50" />
    <ext:Hidden ID="HiddenVerplicht" runat="server" />
    <ext:GridPanel ID="GridPanelSpecificatie" runat="server" Layout="FitLayout" Scroll="Vertical" AutoScroll="true" Flex="1">
        <Store>
            <ext:Store runat="server">
                <Model>
                    <ext:Model runat="server" IDProperty="Id">
                        <Fields>
                            <ext:ModelField Name="Id" />
                            <ext:ModelField Name="Naam" />
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
        </Store>
        <ColumnModel>
            <Columns>
                <ext:Column runat="server" DataIndex="Naam" Flex="1" Border="false" />
            </Columns>
        </ColumnModel>
        <SelectionModel>
            <ext:CheckboxSelectionModel ID="CheckboxSelectionModel_GridPanelSpecificatie" runat="server">
                <Listeners>
                    <SelectionChange Fn="GridPanelSpecificatie_SelectionChange" />
                </Listeners>
            </ext:CheckboxSelectionModel>
        </SelectionModel>
    </ext:GridPanel>
    Page Code
    // called every page load to recreate the panels
     private void PanelSpecificatiesLaden()
            {
                // init 
                List<Specificatie> AlleSpecificaties = Helper.Functies.Specificaties.AlleSpecificatiesLaden();
    
                // 
                foreach (var Specificatie in AlleSpecificaties)
                {
                    // control - gridpanel
                    var CtrlSpecificatie = this.LoadControl("~/controls/gridpanels/specificatie_gridpanel.ascx") as specificatie_gridpanel;
                    CtrlSpecificatie.ID = "CtrlSpecificatie_" + Specificatie.Id;
                    CtrlSpecificatie.Specificatie = Specificatie;
                    
                    // panel
                    var PanelSpecificatie = new Panel();
                    PanelSpecificatie.ID = "PanelSpecificatie_" + Specificatie.Id;
                    PanelSpecificatie.BodyPadding = 10;
                    PanelSpecificatie.Layout = "VBoxLayout";
                    PanelSpecificatie.LayoutConfig.Add(new VBoxLayoutConfig { Pack = BoxPack.Start, Align = VBoxAlign.Stretch });
                    PanelSpecificatie.ContentControls.Add(CtrlSpecificatie);
                    PanelSpecificatie.Listeners.Activate.Fn = "SpecificatiesWizardPanel_Activatie";
    
                    // toevoegen
                    PanelStappenWizard.Items.Add(PanelSpecificatie);
                }
    
            }
    
    
    // code to get the selection from the gridpanel
     private void GetSelectedRows()
            {
                // init 
                List<Specificatie> AlleSpecificaties = Helper.Functies.Specificaties.AlleSpecificatiesLaden();
    
              foreach (var Specificatie in AlleSpecificaties)
                    {
                        var CtrlSpecificatie = ControlUtils.FindControl<specificatie_gridpanel>(this, "CtrlSpecificatie_" + Specificatie.Id);
                        var GridPanelSpecificatie = ControlUtils.FindChildControl(CtrlSpecificatie, "GridPanelSpecificatie") as GridPanel;
    
                        if (GridPanelSpecificatie != null)
                        {
                            var SelectieModel = GridPanelSpecificatie.GetSelectionModel() as CheckboxSelectionModel;
    
                            foreach (var Record in SelectieModel.SelectedRows)
                            {
                               // the count is always 0
                            }
                        }
                    }
    
            }
  2. #2
    Hi,

    Please send the full code so that i can test.
  3. #3
    Hi yash.kapoor,

    This thread can be closed. I've created my setup in codebehind instead of using a usercontrol. Now everything works perfect:

    
                foreach (var Specificatie in AlleSpecificaties)
                {
                    // control - gridpanel
                    //var CtrlSpecificatie = this.LoadControl("~/controls/gridpanels/specificatie_gridpanel.ascx") as specificatie_gridpanel;
                    //CtrlSpecificatie.ID = "CtrlSpecificatie_" + Specificatie.Id;
                    //CtrlSpecificatie.Specificatie = Specificatie;
    
                    // panel
                    var PanelSpecificatie = new Panel
                    {
                        ID = "PanelSpecificatie_" + Specificatie.Id,
                        BodyPadding = 10,
                        Layout = "VBoxLayout",
                        LayoutConfig = {
                            new VBoxLayoutConfig{ Pack = BoxPack.Start, Align = VBoxAlign.Stretch }
                        },
                        Listeners =
                        {
                            Activate = { Fn = "SpecificatiesWizardPanel_Activatie" }
                        }
                    };
    
                    // titel
                    var LabelTitel = new Label
                    {
                        ID = "LabelTitel_" + Specificatie.Id,
                        Height = 50,
                        Html = "<h1>[Stap " + iStap + "] - Selecteer de product specificaties - " + Specificatie.Naam + ".</h1>"
                    };
    
                    // hidden
                    var HiddenVerplicht = new Hidden
                    {
                        ID = "HiddenVerplicht_" + Specificatie.Id,
                        Value = Specificatie.Verplicht
                    };
    
                    // gridpanel
                    var GridPanelSpecificatie = new GridPanel
                    {
                        ID = "GridPanelSpecificatie_" + Specificatie.Id,
                        Layout = "FitLayout",
                        Scroll = ScrollMode.Vertical,
                        AutoScroll = true,
                        Flex = 1,
                        Store = {
                            new Store{
                                Model = {
                                    new Model{
                                        IDProperty = "Id",
                                        Fields = {
                                            new ModelField("Id"),
                                            new ModelField("Naam")
                                        }
                                    }
                                },
                                DataSource = Specificatie.SpecificatieItems
                            }
                        },
                        ColumnModel =
                        {
                            Columns = {
                                new Column {DataIndex = "Naam", Flex= 1, Border= false }
                            }
                        },
                        SelectionModel = {
                            new CheckboxSelectionModel {
                                ID = "CheckboxSelectionModel_GridPanelSpecificatie_" + Specificatie.Id,
                                Listeners = {
                                    SelectionChange = { Fn = "GridPanelSpecificatie_SelectionChange" }
                                }
                            }
                        }
                    };
    
                    PanelSpecificatie.Items.Add(LabelTitel);
                    PanelSpecificatie.Items.Add(HiddenVerplicht);
                    PanelSpecificatie.Items.Add(GridPanelSpecificatie);
                    PanelSpecificatie.AddTo(PanelStappenWizard);
    
                    // gevonden specificatie
                    if (CategorieSpecificaties.Distinct().Contains(Specificatie))
                    {
                        iStap++;
                    }
                    else
                    {
                        PanelStappenWizard.Remove(PanelSpecificatie);
                    }
                }

Similar Threads

  1. Replies: 1
    Last Post: Oct 16, 2012, 9:19 AM
  2. [CLOSED] How to get selectedrows of gridpanel
    By egvt in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 31, 2012, 7:10 PM
  3. Replies: 13
    Last Post: Mar 29, 2012, 2:39 PM
  4. Replies: 0
    Last Post: Oct 26, 2011, 1:16 PM
  5. Replies: 0
    Last Post: Dec 29, 2008, 8:19 AM

Tags for this Thread

Posting Permissions