This is a migrated thread and some comments may be shown as answers.
Finding control within Radgrid formtemplate
5 Answers 198 Views
This is a migrated thread and some comments may be shown as answers.
Robert Jakech
Top achievements
Rank 1
Robert Jakech asked on 23 Nov 2010, 04:30 AM
I have a radgrid (master detail) as shown below in the code snippets. I want to access a control (TextBox) within another control's (Checkbox) checked_changed event. Please i need your assistance.

Let's say, i need to access the control as follows:

Protected void OnCheckedChanged(object sender, EventsArg e)
{
// I need to find a control here.the control shown in code 'ShortTextBox'
}
Thanks in advance.

Robert
         </Columns>
        </MasterTableView>
    </rad:RadGrid>
<rad:RadGrid ID="qualRadGrid" runat="server" AllowAutomaticDeletes="false" AllowAutomaticInserts="false"
        AllowAutomaticUpdates="false" AllowPaging="True"  OnInsertCommand="qualRadGrid_InsertCommand"
        OnDeleteCommand="CategoryGrid_DeleteCommand" OnUpdateCommand="qualRadGrid_UpdateCommand"
        AllowSorting="True" AutoGenerateColumns="False" DataSourceID="ProgrammeDs" EnableAJAX="False"
        GridLines="None" RadControlsDir="~/Resources/RadControls/" Skin="Web20" SkinsPath="~/Resources/RadControls/Grid/Skins"
        Width="750px">
        <MasterTableView AllowMultiColumnSorting="True"  DataKeyNames="ProgId" DataSourceID="ProgrammeDs"
            CommandItemDisplay="Top" Name="Programme">
            <DetailTables>
                <rad:GridTableView  runat="server" CommandItemDisplay="Top" DataKeyNames="QualId"  DataSourceID="QualificationDs"
                    Name="Qualification" AllowMultiColumnSorting="True" AllowAutomaticDeletes="false"
                    AllowAutomaticInserts="false" AllowAutomaticUpdates="false">
                    <ParentTableRelation>
                        <rad:GridRelationFields DetailKeyField="ProgrammeId" MasterKeyField="ProgId" />
                    </ParentTableRelation>
                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px" />
                    </ExpandCollapseColumn>
                    <Columns>
                        <rad:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="~/Resources/Buttons/EditButton.jpg">
                        </rad:GridEditCommandColumn>
                        <rad:GridBoundColumn DataField="QualId" HeaderButtonType="TextButton" HeaderText="Qual Id"
                            SortExpression="QualId" UniqueName="QualId" Visible="false">
                        </rad:GridBoundColumn>
                        <rad:GridBoundColumn DataField="QualDescription" HeaderButtonType="TextButton" HeaderText="Short Description"
                            UniqueName="ShortDesc">
                        </rad:GridBoundColumn>
                    </Columns>
                    <EditFormSettings EditFormType="Template">
                        <FormTemplate>
                            <table id="editableTables-1">
                                <tr>
                                    <td>
                                        <asp:Label ID="Label1" runat="server">Short Description:</asp:Label>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="ShortTextBox" Text='<%# Eval("QualDescription") %>' Width="155px"
                                            runat="server" TextMode="MultiLine" Height="30">
                                        </asp:TextBox>
                                        <asp:RequiredFieldValidator ValidationGroup="validD" id="ReqSponsorTextBox" runat="server" ErrorMessage="*" ControlToValidate="ShortTextBox"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                <td>
                                <asp:CheckBox ID="requiresSubjects" runat="server" Text="Requires Subjects:" AutoPostBack="true" OnCheckedChanged="FindTextBox_OnIndexChanged" />
                                </td>
                                <td>
                                 <telerik:RadComboBox ID="subjectsCombo" EnableLoadOnDemand="true" AutoPostBack="true" MarkFirstMatch="true"  OnItemsRequested="OnItemsRequested_getSubjects" runat="server" RadControlsDir="~/Resources/RadControls/Combobox/Skins" Width="155px" Skin="WebBlue" SkinsPath="~/Resources/RadControls/Combobox/Skins/">
                                        </telerik:RadComboBox>
                                </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:ImageButton ID="LinkInsert" ValidationGroup="validD" Text='<%# (Container is Telerik.WebControls.GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                            ImageUrl="~/Resources/Buttons/SaveButton.jpg" runat="server" CommandName='<%# (Container is Telerik.WebControls.GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                            Visible='<%# (Container is Telerik.WebControls.GridEditFormInsertItem) ? true : false %>' />
                                        <asp:ImageButton ID="LinkButton1" Text='<%# (Container is Telerik.WebControls.GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                            ImageUrl="~/Resources/Buttons/SaveButton.jpg" runat="server" CommandName='<%# (Container is Telerik.WebControls.GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                            Visible='<%# (Container is Telerik.WebControls.GridEditFormInsertItem) ? false : true %>' />
                                        <asp:ImageButton ID="LinkButtonCancel" ImageUrl="~/Resources/Buttons/CancelButton.jpg"
                                            runat="server" Text="Cancel" CausesValidation="false" CommandName="Cancel" />
                                    </td>
                                </tr>
                                <td>
                                    <tr>
                                        <td>
                                            <asp:TextBox ID="IDTextBox" Text='<%# Eval("QualId") %>' runat="server" Visible="false">
                                            </asp:TextBox>
                                        </td>
                                    </tr>
                            </table>
                        </FormTemplate>
                        <EditColumn UniqueName="EditCommandColumn1">
                        </EditColumn>
                    </EditFormSettings>
                </rad:GridTableView>
            </DetailTables>
            <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn Visible="True">
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <%--<rad:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="~/Resources/Buttons/EditButton.jpg">
                </rad:GridEditCommandColumn>--%>
                <rad:GridBoundColumn DataField="ProgId" HeaderText="Programme ID" SortExpression="ProgId"
                    UniqueName="ProgId" Visible="false">
                </rad:GridBoundColumn>
                <rad:GridBoundColumn DataField="ProgCode" HeaderText="Programme Code" SortExpression="ProgCode" ConvertEmptyStringToNull="false"
                    UniqueName="ProgCode">
                </rad:GridBoundColumn>
                <rad:GridBoundColumn DataField="ProgrammeName" HeaderText="Programme Name" SortExpression="ProgrammeName" ConvertEmptyStringToNull="false"
                    UniqueName="ProgrammeName">
                </rad:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </rad:RadGrid>

<rad:RadGrid ID="qualRadGrid" runat="server" AllowAutomaticDeletes="false" AllowAutomaticInserts="false"
        AllowAutomaticUpdates="false" AllowPaging="True"  OnInsertCommand="qualRadGrid_InsertCommand" 
        OnDeleteCommand="CategoryGrid_DeleteCommand" OnUpdateCommand="qualRadGrid_UpdateCommand"
        AllowSorting="True" AutoGenerateColumns="False" DataSourceID="ProgrammeDs" EnableAJAX="False"
        GridLines="None" RadControlsDir="~/Resources/RadControls/" Skin="Web20" SkinsPath="~/Resources/RadControls/Grid/Skins"
        Width="750px">
        <MasterTableView AllowMultiColumnSorting="True"  DataKeyNames="ProgId" DataSourceID="ProgrammeDs"
            CommandItemDisplay="Top" Name="Programme">
            <DetailTables>
                <rad:GridTableView  runat="server" CommandItemDisplay="Top" DataKeyNames="QualId"  DataSourceID="QualificationDs"
                    Name="Qualification" AllowMultiColumnSorting="True" AllowAutomaticDeletes="false"
                    AllowAutomaticInserts="false" AllowAutomaticUpdates="false">
                    <ParentTableRelation>
                        <rad:GridRelationFields DetailKeyField="ProgrammeId" MasterKeyField="ProgId" />
                    </ParentTableRelation>
                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px" />
                    </ExpandCollapseColumn>
                    <Columns>
                        <rad:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="~/Resources/Buttons/EditButton.jpg">
                        </rad:GridEditCommandColumn>
                        <rad:GridBoundColumn DataField="QualId" HeaderButtonType="TextButton" HeaderText="Qual Id"
                            SortExpression="QualId" UniqueName="QualId" Visible="false">
                        </rad:GridBoundColumn>
                        <rad:GridBoundColumn DataField="QualDescription" HeaderButtonType="TextButton" HeaderText="Short Description"
                            UniqueName="ShortDesc">
                        </rad:GridBoundColumn>
                    </Columns>
                    <EditFormSettings EditFormType="Template">
                        <FormTemplate>
                            <table id="editableTables-1">
                                <tr>
                                    <td>
 r<asp:Label ID="Label1" runat="server">Short Description:</asp:Label>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="ShortTextBox" Text='<%# Eval("QualDescription") %>' Width="155px"
                                            runat="server" TextMode="MultiLine" Height="30">
                                        </asp:TextBox>
                                        <asp:RequiredFieldValidator ValidationGroup="validD" id="ReqSponsorTextBox" runat="server" ErrorMessage="*" ControlToValidate="ShortTextBox"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                <td>
                                <asp:CheckBox ID="requiresSubjects" runat="server" Text="Requires Subjects:" AutoPostBack="true" OnCheckedChanged="FindTextBox_OnIndexChanged" />
                                </td>
                                <td>
                                 <telerik:RadComboBox ID="subjectsCombo" EnableLoadOnDemand="true" AutoPostBack="true" MarkFirstMatch="true"  OnItemsRequested="OnItemsRequested_getSubjects" runat="server" RadControlsDir="~/Resources/RadControls/Combobox/Skins" Width="155px" Skin="WebBlue" SkinsPath="~/Resources/RadControls/Combobox/Skins/">
                                        </telerik:RadComboBox>
                                </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:ImageButton ID="LinkInsert" ValidationGroup="validD" Text='<%# (Container is Telerik.WebControls.GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                            ImageUrl="~/Resources/Buttons/SaveButton.jpg" runat="server" CommandName='<%# (Container is Telerik.WebControls.GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                            Visible='<%# (Container is Telerik.WebControls.GridEditFormInsertItem) ? true : false %>' />
                                        <asp:ImageButton ID="LinkButton1" Text='<%# (Container is Telerik.WebControls.GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                            ImageUrl="~/Resources/Buttons/SaveButton.jpg" runat="server" CommandName='<%# (Container is Telerik.WebControls.GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                            Visible='<%# (Container is Telerik.WebControls.GridEditFormInsertItem) ? false : true %>' />
                                        <asp:ImageButton ID="LinkButtonCancel" ImageUrl="~/Resources/Buttons/CancelButton.jpg"
                                            runat="server" Text="Cancel" CausesValidation="false" CommandName="Cancel" />
                                    </td>
                                </tr>
                                <td>
                                    <tr>
                                        <td>
                                            <asp:TextBox ID="IDTextBox" Text='<%# Eval("QualId") %>' runat="server" Visible="false">
                                            </asp:TextBox>
                                        </td>
                                    </tr>
                            </table>
                        </FormTemplate>
                        <EditColumn UniqueName="EditCommandColumn1">
                        </EditColumn>
                    </EditFormSettings>
                </rad:GridTableView>
            </DetailTables>
            <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn Visible="True">
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <%--<rad:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="~/Resources/Buttons/EditButton.jpg">
                </rad:GridEditCommandColumn>--%>
                <rad:GridBoundColumn DataField="ProgId" HeaderText="Programme ID" SortExpression="ProgId"
                    UniqueName="ProgId" Visible="false">
                </rad:GridBoundColumn>
                <rad:GridBoundColumn DataField="ProgCode" HeaderText="Programme Code" SortExpression="ProgCode" ConvertEmptyStringToNull="false"
                    UniqueName="ProgCode">
                </rad:GridBoundColumn>
                <rad:GridBoundColumn DataField="ProgrammeName" HeaderText="Programme Name" SortExpression="ProgrammeName" ConvertEmptyStringToNull="false"
                    UniqueName="ProgrammeName">
                </rad:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </rad:RadGrid>

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 23 Nov 2010, 06:07 AM
Hello Robert,

In order to achieve this first access the edit form using NamingContainer property of CheckBox and then access the TextBox using FindControl() method.

C#:
protected void FindTextBox_OnIndexChanged(object sender, EventArgs e)
   {
       CheckBox chkbox = (CheckBox)sender;
       GridEditFormItem editItem = (GridEditFormItem)chkbox.NamingContainer;
       TextBox txtbox = (TextBox)editItem.FindControl("ShortTextBox"); // accessing the TextBox control
   }

Thanks,
Princy.
0
Robert Jakech
Top achievements
Rank 1
answered on 23 Nov 2010, 09:54 AM
Princy, you are a life saviourrrrrrrrr! 
Long live Telerik!
0
Alex Fefer
Top achievements
Rank 1
answered on 24 Sep 2012, 05:08 PM
How can I do the same from the RadGrid.EditCommand?
Protected Sub radgridHistory_EditCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles radgridHistory.EditCommand
Thanks
0
Princy
Top achievements
Rank 1
answered on 25 Sep 2012, 04:08 AM
Hi Alex,

You can access the controls in ItemDataBound event as shown below.
VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then
        Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
        Dim txt As TextBox = DirectCast(item.FindControl("TextBox1"), TextBox)
    End If
End Sub

Thanks,
Princy.
0
Nick
Top achievements
Rank 1
answered on 22 May 2015, 02:47 PM

You saved me man!

Thanks a Ton..

Tags
Grid
Asked by
Robert Jakech
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Robert Jakech
Top achievements
Rank 1
Alex Fefer
Top achievements
Rank 1
Nick
Top achievements
Rank 1
Share this question
or