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

Help: Accessing a control within a template

2 Answers 33 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ADe
Top achievements
Rank 1
ADe asked on 23 Sep 2008, 04:35 PM
I have a RadCombo within a GridTemplateColumn. How do I reference the combo from code?

Here's the aspx, (it's the bit in pink i'm after),

<telerik:RadGrid ID="radGridUsers" runat="server" AllowPaging="True" Skin="Telerik" GridLines="None" OnEditCommand="radGridUsers_EditCommand" AllowSorting="True" AutoGenerateColumns="False" OnItemCreated="radGridUsers_ItemCreated">  
 
    <pagerstyle nextpagetext="Next" prevpagetext="Prev" mode="NextPrevAndNumeric"></pagerstyle> 
    <mastertableview commanditemdisplay="Top" datakeynames="userName">  
        <Columns> 
            <telerik:GridButtonColumn CommandArgument="Select {0}" UniqueName="column" Text="Select" CommandName="Select" DataTextFormatString="Select {0}"></telerik:GridButtonColumn> 
            <telerik:GridBoundColumn DataField="userName" UniqueName="userName" HeaderText="User Name"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="surName" UniqueName="surName" HeaderText="Last Name"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="foreName" UniqueName="foreName" HeaderText="First Name"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="dateOfBirth" UniqueName="dateOfBirth" HeaderText="Date of Birth"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="templateName" UniqueName="templateName" HeaderText="Role"></telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="currentStatus" UniqueName="currentStatus" HeaderText="Status"></telerik:GridBoundColumn> 
            <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Action">  
                    <ItemTemplate> 
                      <telerik:RadComboBox ID="radComboActions" runat="server">  
                        <Items> 
                          <telerik:RadComboBoxItem Text="-- Action Menu --" /> 
                          <telerik:RadComboBoxItem Text="Edit" /> 
                          <telerik:RadComboBoxItem Text="Enable/Disable" /> 
                          <telerik:RadComboBoxItem Text="Reset Password" /> 
                        </Items> 
                      </telerik:RadComboBox>    
                    </ItemTemplate> 
            </telerik:GridTemplateColumn> 
        </Columns> 
 
        <ExpandCollapseColumn> 
        <HeaderStyle Width="20px"></HeaderStyle> 
        </ExpandCollapseColumn> 
 
        <RowIndicatorColumn> 
        <HeaderStyle Width="20px"></HeaderStyle> 
        </RowIndicatorColumn> 
    </mastertableview> 
      
    <filtermenu enabletheming="True">  
    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    </filtermenu> 
</telerik:RadGrid> 

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 23 Sep 2008, 04:54 PM
Hello ADe,

Try this approach:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    GridDataItem item = e.Item as GridDataItem; 
    if (item != null
    { 
        RadComboBox radComboBox = item["TemplateColumn"].FindControl("RadComboBox1"as RadComboBox; 
        if (radComboBox != null
        { 
            //do something 
        } 
    } 

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
ADe
Top achievements
Rank 1
answered on 23 Sep 2008, 07:16 PM
That worked perfectly. Thankyou very much.
Tags
Grid
Asked by
ADe
Top achievements
Rank 1
Answers by
Daniel
Telerik team
ADe
Top achievements
Rank 1
Share this question
or