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

Can not get reference of control in EditForm FormTemplate

2 Answers 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 08 Aug 2012, 01:14 AM
Hi

I have been trying for way too long but cannot get this to work. When I click on "edit" in the grid, the edit form pops down and I can update/delete as per usual etc.

However when I click on "edit", I want to put certain value in the RadAutoCompleteBox control. I have tried everything to get a reference to that control, IsInEditMode is always false true.

Please can anyone help? Thanks.

<telerik:RadGrid runat="server" ID="RadGrid1" DataSourceID="DS1" AutoGenerateColumns="false" OnItemCommand="RadGrid1_ItemCommand" OnEditCommand="RadGrid1_EditCommand" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true">
    <MasterTableView DataKeyNames="Id" DataSourceID="DS1" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" EditMode="EditForms">
        <Columns>
            <telerik:GridBoundColumn HeaderText="Title" DataField="Title" />
            <telerik:GridEditCommandColumn ButtonType="LinkButton" UniqueName="EditCommandColumn" />
            <telerik:GridButtonColumn ConfirmText="Delete?" ConfirmDialogType="Classic" ConfirmTitle="Delete" ButtonType="LinkButton" CommandName="Delete" Text="Delete" />
        </Columns>
        <EditFormSettings EditFormType="Template">
            <FormTemplate>
                <table>
                    <tr>
                        <th>Search:</th>
                        <td colspan="2"><telerik:RadAutoCompleteBox runat="server" ID="RadAutoCompleteBox1" DataSourceID="DS2" Filter="StartsWith" DataTextField="Text" DataValueField="Value" InputType="Token" Width="100%" DropDownWidth="300px" DropDownHeight="200px" /></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <asp:Button ID="btnUpdate" Text="Update" runat="server" CommandName="Update" />
                            <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button>
                        </td>
                        <td></td>
                    </tr>
                </table>
            </FormTemplate>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>
    

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Aug 2012, 04:44 AM
Hi,

You can access the controls in FormTemplate in ItemDataBound event as shown below. Also take a look into this demo.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
 {
   GridEditFormItem item = (GridEditFormItem)e.Item;
   RadAutoCompleteBox auto = (RadAutoCompleteBox)item.FindControl("RadAutoCompleteBox1");
 }
}

Thanks,
Shinu.
0
Michael
Top achievements
Rank 1
answered on 08 Aug 2012, 11:53 PM
Thanks so much it worked. I missed trying OnItemDataBound argghhh
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Share this question
or