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

How to get the Controls of a dynamically created GridTemplateColumn inside Telerik:RadGrid

2 Answers 90 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tony Liu
Top achievements
Rank 1
Tony Liu asked on 07 Dec 2012, 05:45 AM

private void RadGrid_InitCol()
 {
       RadGrid1.AutoGenerateColumns = false;
       RadGrid1.Columns.Clear();
       GridBoundColumn boundColumn;
  
       boundColumn = new GridBoundColumn();
       boundColumn.DataField = "id";
       boundColumn.HeaderText = "id";
       boundColumn.UniqueName = "id";
       boundColumn.HeaderStyle.Width = Unit.Pixel(60);
       boundColumn.Visible = false;
       RadGrid1.MasterTableView.Columns.Add(boundColumn);
 
       String templateColName = "SO2";
       GridTemplateColumn templateColumn;
       templateColumn = new GridTemplateColumn() {
           UniqueName = "tempCol0",
           HeaderText = templateColName,
           ItemTemplate = new MyTemplate("0", templateColName)
           //EditItemTemplate = new MyEditTemplate(templateColName)   
       };
       RadGrid1.MasterTableView.Columns.Add(templateColumn);
}

protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
{
        if (e.Argument == string.Empty)
        {
             RadGrid1.Rebind();
             return;
        }
 
        String[] editedItemIds = e.Argument.Trim(':').Split(':');
        int i;
        for (i = 0; i < editedItemIds.Length; i++)
        {
            string id = editedItemIds[i];
            GridDataItem updatedItem = RadGrid1.MasterTableView.FindItemByKeyValue("id", int.Parse(id));
            TextBox txtBox = (TextBox)updatedItem.FindControl("txtBox");
         }
}

updatedItem["id"].Text=115102
updatedItem["tempCol0"] .Text=""  updatedItem["tempCol0"] .Controls.Count=0
-------------------------------------------------------------------------------------------------------------------------------
How to get the txtbox control?


Thanks!

2 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 12 Dec 2012, 09:30 AM
Hi Tony,

Please ensure that you are creating the GridTemplateColumn correctly in the Page_Init event as shown below:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html

Also see the following help topic for more information on accessing the items in the Template Column:
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html
Kind regards,
Maria Ilieva
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
Tony Liu
Top achievements
Rank 1
answered on 15 Dec 2012, 06:45 AM
I will check the code.

Thank you for the reply!
Tags
Grid
Asked by
Tony Liu
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Tony Liu
Top achievements
Rank 1
Share this question
or