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

How to find Child Controls in the RadGrid from codebehined

1 Answer 260 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ranganath
Top achievements
Rank 1
Ranganath asked on 20 Jul 2008, 10:22 AM

Hi,

How to find child controls that are located under the  <FormTemplate> tag of RadControl.

<telerik:RadGrid PageSize="3" AllowPaging="true" ID="RadGrid1" runat="server" GridLines="Horizontal"

        AllowFilteringByColumn="true" Skin="WebBlue" AllowAutomaticDeletes="True" OnNeedDataSource="RadGrid1_NeedDataSource"

        OnDeleteCommand="RadGrid1_DeleteCommand" OnInsertCommand="RadGrid1_InsertCommand"

        OnUpdateCommand="RadGrid1_UpdateCommand"

        onitemcommand="RadGrid1_ItemCommand" onitemcreated="RadGrid1_ItemCreated">

        <PagerStyle Mode="Slider" />

        <MasterTableView AutoGenerateColumns="false" DataKeyNames="TerritoryID" EditMode="EditForms"

            CommandItemDisplay="TopAndBottom">

            <Columns>

                <telerik:GridEditCommandColumn>

                </telerik:GridEditCommandColumn>

                <telerik:GridBoundColumn ReadOnly="true" HeaderText="TerritoryID" DataField="TerritoryID"

                    UniqueName="TerritoryID" />

                <telerik:GridBoundColumn ReadOnly="false" HeaderText="TerritoryDescription" DataField="TerritoryDescription"

                    UniqueName="TerritoryDescription" />

                <telerik:GridBoundColumn ReadOnly="false" HeaderText="RegionID" DataField="RegionID"

                    UniqueName="RegionID" />

                <telerik:GridButtonColumn CommandName="Delete" Text="Delete">

                </telerik:GridButtonColumn>

            </Columns>

            <EditFormSettings EditFormType="Template">

                <EditColumn UniqueName="EditCommandColumn1">

                </EditColumn>

                <FormTemplate>

                    <table id="Table2" cellspacing="2" cellpadding="1" width="250" border="1" rules="none"

                        style="border-collapse: collapse">

                        <tr>

                            <td>

                                <table id="Table3" cellspacing="1" cellpadding="1" width="250" border="0">

                                    <tr>

                                        <td>

                                        </td>

                                        <td>

                                        </td>

                                    </tr>

                                    <tr>

                                        <td>

                                            TerritoryID:

                                        </td>

                                        <td>

                                            <asp:TextBox ID="txtTerritoryID" MaxLength="5" Visible='<% # (Container as GridItem).OwnerTableView.IsItemInserted %>'

                                                runat="server">

                                            </asp:TextBox>

                                        </td>

                                    </tr>

                                    <tr>

                                        <td>

                                            TerritoryDescription:

                                        </td>

                                        <td>

                                                                                     <asp:CheckBox ID="CheckBox1" runat="server"></asp:CheckBox>

                                        </td>

                                    </tr>

                                    <tr>

                                        <td>

                                            RegionID:

                                        </td>

                                        <td>

                                            <asp:TextBox ID="txtRegionID" runat="server" Text='<%# Eval( "RegionID") %>' TabIndex="1">

                                            </asp:TextBox>

                                        </td>

                                    </tr>

                                </table>

                            </td>

                        </tr>

                        <tr>

                            <td colspan="2">

                                <b>Territory Info:</b>

                            </td>

                        </tr>

                        <tr>

                            <td align="right" colspan="2">

                                <asp:Button ID="btnUpdate" Text='<%# (Container as GridItem).OwnerTableView.IsItemInserted ? "Insert" : "Update" %>'

                                    runat="server" CommandName='<%# (Container as GridItem).OwnerTableView.IsItemInserted ? "PerformInsert" : "Update" %>'>

                                </asp:Button>&nbsp;

                                <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"

                                    CommandName="Cancel"></asp:Button>

                            </td>

                        </tr>

                    </table>

                </FormTemplate>

            </EditFormSettings>

        </MasterTableView>

    </telerik:RadGrid>

I want to Find out that Controls which I placed inside the RadGrid , such as txtRegionID, CheckBox1…. From code behind.So that I can bind my required data to the thouse controls.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Jul 2008, 05:44 AM
Hello Ranganath,

Try accessing the controls in the FormTemplate of the RadGrid as shown below.

CS:
  protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
 
        if( (e.Item is GridEditableItem )&&(e.Item.IsInEditMode)) 
        { 
            GridEditableItem formItem = (GridEditableItem)e.Item; 
            TextBox txtRegionID = (TextBox)formItem.FindControl("txtRegionID"); 
            CheckBox CheckBox1 = (CheckBox)formItem.FindControl("CheckBox1");     
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Ranganath
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or