Grid Template Column programmatically

15 posts, 0 answers
  1. balaji
    balaji avatar
    17 posts
    Member since:
    Dec 2010

    Posted 17 Dec 2010 Link to this post

    Hi,

    I suppose to create a grid template column in code behind with dropdown in edit item template and label in item template as usual. I'm new telerik.. Plz help me...
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Dec 2010 Link to this post

    Hello Balaji,

    Please refer the following documentation which explains how to create GridTemplateColumn programitically.
    http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html

    Thanks,
    Princy.
  3. balaji
    balaji avatar
    17 posts
    Member since:
    Dec 2010

    Posted 17 Dec 2010 Link to this post

    hi princy,

    thanx for the reply. Do you have any sample/demo/doc which explain better then help doc.


  4. balaji
    balaji avatar
    17 posts
    Member since:
    Dec 2010

    Posted 17 Dec 2010 Link to this post

    hi all,

    could anybody help me on this. i want to bind dropdown in edit item template @ Edit Command

    regards,

    Balaji.R
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Dec 2010 Link to this post

    Hello Balaji,


    Use the same logic as desribed in documentation for craeting the GridTemplateColumn. Now access the control in ItemDataBound event and set the DataSource from code behind.

    Sample code:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridEditFormItem && !e.Item.IsInEditMode)
            {
                GridEditFormItem editItem = (GridEditFormItem)e.Item;
                RadComboBox combo = (RadComboBox)editItem.FindControl("controlID");
                combo.DataSource = dt; // set the datasource here            
            }      
        }



    Thanks,
    Princy.
  6. balaji
    balaji avatar
    17 posts
    Member since:
    Dec 2010

    Posted 21 Dec 2010 Link to this post

    hi princy

    thanx again for your reply. i've gone through the document

    this is how i made template column for edit and item. I 'm not able to make this work in edit mode.

    GridTemplateColumn templateColumn = new GridTemplateColumn();
    templateColumn.EditItemTemplate = new MyEditTemplate(templateColumnName);
    templateColumn.ItemTemplate = new MyTemplate(templateColumnName);
    templateColumn.HeaderText = _i2Object._i2Arguments[i].DisplayName;
    templateColumn.DataField = _i2Object._i2Arguments[i].DataTextField;
    this.RadGrid1.MasterTableView.Columns.Add(templateColumn);

    public class MyTemplate : ITemplate
       {       
           protected RequiredFieldValidator validatorTextBox;       
           protected TextBox textBox;      
     
           private string colname;
     
           public MyTemplate(string cName)
           {
               colname = cName;
           }
     
           public void InstantiateIn(System.Web.UI.Control container)
           {
               textBox = new TextBox();
               textBox.ID = "templateColumnTextBox";
               textBox.DataBinding += new EventHandler(textBox_DataBinding);
               validatorTextBox = new RequiredFieldValidator();
               validatorTextBox.ControlToValidate = "templateColumnTextBox";
               validatorTextBox.ErrorMessage = "*";
             
               container.Controls.Add(textBox);
               container.Controls.Add(validatorTextBox);                    
     
           }
     
           public void textBox_DataBinding(object sender, EventArgs e)
           {
               TextBox txt = (TextBox)sender;
               GridDataItem container = (GridDataItem)txt.NamingContainer;
               txt.Text = ((DataRowView)container.DataItem)[colname].ToString();
           }
           
       }
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Dec 2010 Link to this post

    Hello Balaji,

    You can refer the following forum which explains how to create EditItemTemplate of GridTemplateColumn programmatically.
    Creating EditItemTemplate of GridTemplateColumn programmatically

    Hope this helps,
    Princy.
  8. Rohan
    Rohan avatar
    94 posts
    Member since:
    Jul 2012

    Posted 20 Nov 2012 Link to this post

    Hi all ,
    I want to put one column in rad grid to select and deselect  one row or multiple row using check box and persistent check box value   during paging and sorting various rad grid Operation  and all these think are done during the run time(dynamically)
    for this i have create one template class , now i am confused for where can i fire the event of check to all selected row details to persistence store to retrieve value to various grid Operation
    my Item Template class declaration 

    public class DataListCustomCheckBoxTemplateColumn:ITemplate
        {
            protected CheckBox checkBox;
            public void InstantiateIn(System.Web.UI.Control container)
            {
                checkBox = new CheckBox();
                checkBox.ID = "chkSelect";
                checkBox.AutoPostBack = true;
                container.Controls.Add(checkBox);
            }
        }
    how can i do this ,please provide any example or document or link to work ......
  9. Eyup
    Admin
    Eyup avatar
    4074 posts

    Posted 23 Nov 2012 Link to this post

    Hello Rohan,

    You could use a GridClientSelectColumn and implement one of the following approaches:
    http://www.telerik.com/help/aspnet-ajax/grid-persist-selected-rows-client-sorting-paging-grouping-filtering.html
    http://www.telerik.com/help/aspnet-ajax/grid-persist-selected-rows-on-sorting.html

    I hope this will prove helpful.

    Regards,
    Eyup
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  10. Rohan
    Rohan avatar
    94 posts
    Member since:
    Jul 2012

    Posted 23 Nov 2012 Link to this post

    Hi Eyup,

    Thanks for your replay .

    I am using GridClientSelectColumn to select row of rad grid . using the this column i am able to select single row and multiple row and these rows are persistence during the various operation or rad grid such as paging ,sorting and grouping .
    i have one button on page that gets all selected rows of radgrid ,but i am not able to get all these row .
    to get all selected rows, i am using following code

    _grdDataListView.MasterTableView.AllowPaging = false;
                    _grdDataListView.Rebind();
                    int aas = _grdDataListView.Items.Count;
                    foreach (GridDataItem item in _grdDataListView.MasterTableView.Items)
                    {

                        CheckBox _chkBox = (CheckBox)item["ClientSelectColumn"].Controls[0];
                        if (_chkBox.Checked == true)
                        {
                            _temp.Add(Convert.ToInt32(item.GetDataKeyValue(this.DataKeyNames[0].ToString())));
                        }
                        //String str = item["ColumnUniqueName"].Text;

                    }
                    _grdDataListView.MasterTableView.AllowPaging = true;
                    _grdDataListView.Rebind();

    after the rebind i am not able to get state of selected row of rad grid ....... i am stuck here .... please provide any example
  11. Eyup
    Admin
    Eyup avatar
    4074 posts

    Posted 27 Nov 2012 Link to this post

    Hi Rohan,

    I have provided an example to your request in the following thread:
    http://www.telerik.com/community/forums/aspnet-ajax/grid/getting-all-the-griddataitems.aspx

    I suggest you to continue our conversation on the mentioned thread so other user with similar requirements could track easily the discussion.

    Greetings,
    Eyup
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  12. Rohan
    Rohan avatar
    94 posts
    Member since:
    Jul 2012

    Posted 28 Nov 2012 Link to this post

    Hi Eyup,

    Thank you very much for you replay and your support..
    your provided solution works for mi... once again thanks for you ...

    one query -
    i creating user control with radgrid , for selecting the row at client side i am using same code ,in that code we are using the "selected" is global variable ... if i am using multiple instance of same user control on page then this variable not working as per as user control instance .. it share the same variable across the all control instances of that page ... how can i do this .

    once again thanks for you replay .
  13. Eyup
    Admin
    Eyup avatar
    4074 posts

    Posted 29 Nov 2012 Link to this post

    Hello Rohan,

    You could assign a unique identificator for the Session variable per User Control basis.

    I hope this helps.

    Kind regards,
    Eyup
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  14. Jack
    Jack avatar
    1 posts
    Member since:
    Apr 2020

    Posted 13 Jun 2020 in reply to Princy Link to this post

    Hello Princys

    I need this artical and cant find it. Please let me know where can I find this link?

  15. Rumen
    Admin
    Rumen avatar
    14437 posts

    Posted 16 Jun 2020 Link to this post

    Hi Jack,

    The forum thread (Creating EditItemTemplate of GridTemplateColumn programmatically) you are looking for is not active anymore since it was for RadControls for ASP.NET which was discontinued in 2009 in favor of RadControls for ASP.NET AJAX - now called Telerik UI for ASP.NET AJAX.

    For your convenience, I pasted the forum thread discussion in a Word file and attached it to my reply.

     

    Regards,
    Rumen
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top