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
1175
Add unbound checkbox column in code
posted
What is the best way to add an unbound checkbox column ? I need to add a control to the Template data field but there is no add method.
  • 1175
    posted

    This is how you can add a template field in the code behind. You have to handle the WebDataGrid’s Init event, and in the Init event handler (WebDataGrid1_Init in the example) do the following


     


          protected void WebDataGrid1_Init(object sender, EventArgs e)


          {


                TemplateDataField tempField = new TemplateDataField();


                tempField.Key = "MyTempField";


                tempField.Header.Text = "My Dynamic Checkbox";


                CompiledBindableTemplateBuilder cbtb = new CompiledBindableTemplateBuilder(new BuildTemplateMethod(BuildCheck), null);


                tempField.ItemTemplate = cbtb;


                this.WebDataGrid1.Columns.Add(tempField);


          }


        
         void BuildCheck (Control ctl)


          {


                IParserAccessor acess = ctl;


                CheckBox ch = new CheckBox();


                ch.ID = "check2";


                acess.AddParsedSubObject(ch);


          }