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

Find control inside InsertItemTemplate

3 Answers 170 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rem
Top achievements
Rank 1
Rem asked on 16 Jan 2014, 07:26 AM
Hi,

I have to find the control inside InsertItemTemplate during itemdatabound.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Jan 2014, 07:54 AM
Hi Rem,

Please have a look into the following code snippet to access a TextBox in InsertItemTemplate:

ASPX:
<telerik:GridTemplateColumn HeaderText="Column1">
    <InsertItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </InsertItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
    {
      GridEditFormInsertItem edit = (GridEditFormInsertItem)e.Item;
      TextBox txt = (TextBox)edit.FindControl("TextBox1"); // Access the Textbox Control         
    }
}

Thanks,
Shinu
0
Rem
Top achievements
Rank 1
answered on 24 Jan 2014, 08:39 AM
Hi,

I tried it, but unable to satisfy the condition GridEditFormInsertItem. My code is;

<telerik:RadGrid ID="gvAllergies" runat="server" GridLines="None" AllowAutomaticDeletes="True"
                    AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="False" Width="96%"
                    CellSpacing="0" Skin="Outlook" AllowAutomaticInserts="true">
                    <ClientSettings EnablePostBackOnRowClick="false">
                        <ClientEvents OnRowCreated="RowCreated" />
                    </ClientSettings>
                    <MasterTableView CommandItemDisplay="Bottom" CommandItemSettings-AddNewRecordText=""
                        CommandItemSettings-CancelChangesText="" InsertItemDisplay="Bottom" HorizontalAlign="NotSet"
                        EditMode="Batch" AutoGenerateColumns="False" ItemStyle-Height="25px" CommandItemSettings-ShowSaveChangesButton="false"
                        CommandItemSettings-ShowRefreshButton="false" DataKeyNames="Counter">
                        <CommandItemSettings AddNewRecordText="" ShowAddNewRecordButton="true" CancelChangesText=""
                            ShowCancelChangesButton="true" />
                        <BatchEditingSettings EditType="Cell" />
                        <Columns>
                            <telerik:GridBoundColumn FilterControlAltText="Filter No column" UniqueName="No"
                                HeaderText="No." DataField="ID" ReadOnly="true">
                                <ItemStyle HorizontalAlign="Center" />
                                <HeaderStyle HorizontalAlign="Center" />
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn FilterControlAltText="Filter Allergen column" UniqueName="Allergen"
                                HeaderText="Allergen" DataField="Code">
                                <ItemStyle HorizontalAlign="Center" Width="30px" />
                                <HeaderStyle HorizontalAlign="Center" Width="30px" />
                                <ItemTemplate>
                                    <asp:Label ID="lblAllergen" runat="server"></asp:Label>
                                </ItemTemplate>
                                <InsertItemTemplate>
                                    <telerik:RadComboBox ID="cmbAllergen" runat="server" AutoPostBack="false" DataValueField="ID"
                                        AllowCustomText="true" EnableLoadOnDemand="true" DataTextField="Name" OnItemDataBound="cmbAllergen_ItemDataBound"
                                        OnItemsRequested="cmbAllergen_ItemsRequested" Width="200px" DropDownWidth="350px"
                                        Height="400px" HighlightTemplatedItems="true">
                                        <HeaderTemplate>
                                            <table>
                                                <tr>
                                                    <td style="width: 50px" align="center">
                                                        Code
                                                    </td>
                                                    <td align="center">
                                                        Allergen
                                                    </td>
                                                </tr>
                                            </table>
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <table>
                                                <tr>
                                                    <td id="cellCode" runat="server" style="width: 50px">
                                                    </td>
                                                    <td id="cellName" runat="server" align="left">
                                                    </td>
                                                </tr>
                                            </table>
                                        </ItemTemplate>
                                    </telerik:RadComboBox>
                                </InsertItemTemplate>
                                <ItemStyle HorizontalAlign="Center" Width="220px" />
                                <HeaderStyle HorizontalAlign="Center" Width="220px" />
                            </telerik:GridTemplateColumn>
</Columns>
                    </MasterTableView>
                </telerik:RadGrid>

I want to assign clientevent to the combobox from codebehind.
0
Konstantin Dikov
Telerik team
answered on 28 Jan 2014, 05:39 PM
Hi Rem,

I have notice that you are using Batch edit mode, which is handling the editing entirely on client-side and the approach that Shinu provided could not be used with Batch editing. Please note that key element of the batch editing mode is that it uses only one editor for a single column. Detail information could be found at the following help article:

In the help article you will also find information on how to get reference to BatchColumnEditor for each column.

Hope that helps.


Regards,
Konstantin Dikov
Telerik
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 UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Rem
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Rem
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or