This is a migrated thread and some comments may be shown as answers.

Grid Template Column programmatically

14 Answers 1348 Views
Grid
This is a migrated thread and some comments may be shown as answers.
balaji
Top achievements
Rank 1
balaji asked on 17 Dec 2010, 12:05 PM
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...

14 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Dec 2010, 12:39 PM
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.
0
balaji
Top achievements
Rank 1
answered on 17 Dec 2010, 01:40 PM
hi princy,

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


0
balaji
Top achievements
Rank 1
answered on 17 Dec 2010, 02:40 PM
hi all,

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

regards,

Balaji.R
0
Princy
Top achievements
Rank 2
answered on 20 Dec 2010, 07:27 AM
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.
0
balaji
Top achievements
Rank 1
answered on 21 Dec 2010, 06:30 AM
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();
       }
       
   }
0
Princy
Top achievements
Rank 2
answered on 21 Dec 2010, 07:46 AM
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.
0
Rohan
Top achievements
Rank 1
answered on 20 Nov 2012, 11:16 AM
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 ......
0
Eyup
Telerik team
answered on 23 Nov 2012, 09:24 AM
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.
0
Rohan
Top achievements
Rank 1
answered on 23 Nov 2012, 10:51 AM
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
0
Eyup
Telerik team
answered on 27 Nov 2012, 03:16 PM
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.
0
Rohan
Top achievements
Rank 1
answered on 28 Nov 2012, 11:08 AM
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 .
0
Eyup
Telerik team
answered on 29 Nov 2012, 03:12 PM
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.
0
Jack
Top achievements
Rank 1
answered on 13 Jun 2020, 08:48 PM

Hello Princys

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

0
Rumen
Telerik team
answered on 16 Jun 2020, 02:02 PM

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.
Tags
Grid
Asked by
balaji
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
balaji
Top achievements
Rank 1
Rohan
Top achievements
Rank 1
Eyup
Telerik team
Jack
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or