Finding control within Radgrid formtemplate

6 posts, 0 answers
  1. Robert Jakech
    Robert Jakech avatar
    34 posts
    Member since:
    Feb 2010

    Posted 22 Nov 2010 Link to this post

    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>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Nov 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Robert Jakech
    Robert Jakech avatar
    34 posts
    Member since:
    Feb 2010

    Posted 23 Nov 2010 Link to this post

    Princy, you are a life saviourrrrrrrrr! 
    Long live Telerik!
  5. Alex Fefer
    Alex Fefer avatar
    5 posts
    Member since:
    Aug 2007

    Posted 24 Sep 2012 Link to this post

    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
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Sep 2012 Link to this post

    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.
  7. Nick
    Nick avatar
    23 posts
    Member since:
    Jan 2012

    Posted 22 May 2015 in reply to Princy Link to this post

    You saved me man!

    Thanks a Ton..

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017