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

Grid ItenDataBound InsertItemTemplate controls

1 Answer 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 27 Jun 2015, 02:56 AM

Is it possible to access controls in the InsertItemTemplate of the GridTemplateColumn? I have the following:

<telerik:GridTemplateColumn UniqueName="Company" HeaderText="Company Name">
    <ItemTemplate>
        <asp:Label ID="lblName" runat="server" Text='<%#Eval("Name")%>'></asp:Label>
    </ItemTemplate>
    <InsertItemTemplate>
       <telerik:RadAutoCompleteBox runat="server" ID="CompanyList" EmptyMessage="select company"></telerik:RadAutoCompleteBox>
    </InsertItemTemplate>
</telerik:GridTemplateColumn>

In the code behind I have:

if (e.Item is GridEditableItem && e.Item.OwnerTableView.IsItemInserted)
{
    GridEditableItem item = e.Item as GridEditableItem;
    RadAutoCompleteBox ab = item["Company"].FindControl("CompanyList") as RadAutoCompleteBox;
}

I also tried:

if (e.Item is GridDataItem && e.Item.OwnerTableView.IsItemInserted)
{
    GridDataItem item = e.Item as GridDataItem;
    RadAutoCompleteBox ab = item["Company"].FindControl("CompanyList") as RadAutoCompleteBox;
}

In both cases ab returns null. When I placed the control inside ItemTemplate, I get the control. I also tried using FindControl on e.Item and item itself and still get null. Basically I want to add a datasource to the autocomplete box only when inserting...on edit I only show the label. I want to bind the control using Telerik Data Access.

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 01 Jul 2015, 11:53 AM
Hello Tom,

What EditMode do you use? You can examine the approaches provided in the following section to access the generated controls in the edit form:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

Hope this helps.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Tom
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or