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

Get item template control from column

2 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aaron Ellery
Top achievements
Rank 1
Aaron Ellery asked on 04 Jul 2008, 10:43 AM
Hi,

I am using the grid to view a table with multiple foreign keys. Not using a view, so I want to use a bunch of lookup combos to display the human readable descriptions for each foriegn key. To do this im using a rad combo as a template item for the databound cell. My issue is that I can't seem to find how to get an instance of this control in the codebehind so I can populate the list of values for the foreign key. Any ideas on how this could be done or suggestions of how to accomplish this without using a view? Currently I am binding the data via a datatable in the NeedsDatasource event.

aspx im using to declare the combo template is below.

Thanks.

<

Columns>

<telerik:GridBoundColumn DataField="DEPARTMENT_CODE_ID" HeaderText="Department" UniqueName="column1">

</telerik:GridBoundColumn>

<telerik:GridTemplateColumn DataField="MODULE_ID" HeaderText="Module" UniqueName="column3">

<EditItemTemplate>

<asp:TextBox ID="MODULE_IDTextBox" runat="server" Text='<%# Bind("MODULE_ID") %>'></asp:TextBox>

</EditItemTemplate>

<ItemTemplate>

<telerik:RadComboBox ID="RadComboBox1" runat="server" Enabled="False" SelectedValue='<%# Eval("MODULE_ID") %>'>

<Items>


2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 07 Jul 2008, 01:12 PM
Hi Aaron Ellery,

Thank you for contacting us.

You can get an instance of that combobox in ItemCreated:

protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)  
        {  
            if (e.Item is GridDataItem)  
            {  
                RadComboBox comboBox = e.Item.FindControl("RadComboBox1") as RadComboBox;  
            }  
        } 

I hope that's helpful.

Greetings,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Princy
Top achievements
Rank 2
answered on 08 Jul 2008, 07:36 AM
Hi Aaron,

You can also use the UniqueName property to access the Controls inside GridTemplateColumn.

CS:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            RadComboBox comboBox = item["column3"].FindControl("RadComboBox1") as RadComboBox ;  
        }    
    }  
 


Thanks
Princy.
Tags
Grid
Asked by
Aaron Ellery
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Princy
Top achievements
Rank 2
Share this question
or