Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
240
UserControl as rowedittemplate for child band; issues with loading & binding
posted

Infragistics4.Web.v13.1, Version=13.1.20131.2107

I'm trying to utilize a usercontrol as the rowedittemplate for a childband in my WHDG. The idea behind the UC is that it should dynamically represent the data being edited: different controls will be visible for different data in the bands.

Q/P1): is there a way to prevent the UC from being rendered with every childband record? There could be 1000's...

Q/P2): how do I bind serverside to some public properties of the UC? Since it appears the UC instances are loading with every record (see above), I could cut down on the amount of html being rendered by only making visible the controls I am concerned with for each row. Using two public properties "Parameter" and "Selections", I have tried this type of setup in the template:

<ig:RowEditingTemplate CancelButton="buttonCancel" OKButton="buttonOK">
...    
<Template>        
<uc1:ucSetParameter ID="ucSetParameter1" runat="server" Parameter='<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "ParameterName") %>' Selections='<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "CurValue2") %>' />    
</Template>
</ig:RowEditingTemplate>

but cannot determine the correct binding container reference, I either get "not part of namespace" or "doesn't contain this property" errors (I've confirmed the dataset does match the "ParameterName" key & case) whenever I try alternate container references.

Any help appreciated.

Parents
  • 49378
    posted

    Hello arsinfragistics,

     

    Thank you for posting in our community !

    Currently the WHDG does not allow rendering a common row editing template for multiple child bands as the template uniqueness and instantiation per band allows configuring the template for each band individually.

    In this scenario, I would suggest defining a custom template class implementing the ITemplate interface and instantiating the template per-child band based on the specific child band which is being created/expanded.

    This approach is based mostly on the following documentation article:

    http://help.infragistics.com/Help/NetAdvantage/ASPNET/2012.1/CLR4.0/html/WebDataGrid_Using_Client_Bindings.html

    In this case, the RowIslandCreated event is employed for the task:

    protected void WebHierarchicalDataGrid1_RowIslandCreated(object sender, Infragistics.Web.UI.GridControls.RowIslandEventArgs e)
        {
            //get whatever data is needed about the new child band
     
            bool shouldDisplayFirstTemplateLabel = true;
            if (e.RowIsland.Rows.Count < 5)
            {
                shouldDisplayFirstTemplateLabel = false;
            }
            e.RowIsland.Behaviors.EditingCore.Behaviors.RowEditTemplate.Template = new customChildTemplate(shouldDisplayFirstTemplateLabel);
        }
     
     
    }
     
    class customChildTemplate : ITemplate
    {
        public customChildTemplate(bool displayNameLabel1)
         {
            ShouldDisplayLabel1 = displayNameLabel1;
        }
     
        private bool ShouldDisplayLabel1 { getset; }
     
        public void InstantiateIn(Control container)
        {
            if (ShouldDisplayLabel1)
            {
                Label label1 = new Label();
                label1.Text = "CompanyName";
                label1.ID = "NameLabel1";
     
                container.Controls.Add(label1);
            }
            TextBox textBox1 = new TextBox();
            textBox1.ID = "NameTextBox1";
     
            Button b1 = new Button();
            b1.Text = "OK";
            b1.ID = "OkButton";
            b1.UseSubmitBehavior = false;
            b1.OnClientClick = "return";
            b1.CausesValidation = false;
     
            Button b2 = new Button();
            b2.Text = "Cancel";
            b2.ID = "CancelButton";
            b2.UseSubmitBehavior = false;
            b2.OnClientClick = "return";
            b2.CausesValidation = false;
     
            container.Controls.Add(textBox1);
            container.Controls.Add(b1);
            container.Controls.Add(b2);
        }
    }

    The same approach may be used when templating a user control inside the RET. Attached is my sample for your consideration.

     

    Please do not hesitate to contact me if you have any questions. 

    WebDataGridUCRET.zip
Reply Children