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

Edit Template with conditional controls

3 Answers 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Atlas
Top achievements
Rank 1
Atlas asked on 03 Aug 2012, 12:32 AM
I have a grid that uses an edit form template. The template includes a dropdown that needs to control the visibility of other controls on the form based on the selection. I intend to do this with a selected index changed event. How do I get a reference to the edit form controls on the page within a SelectedIndexChanged event of a dropdown?

<EditFormSettings EditFormType="Template">
    <EditColumn ButtonType="ImageButton" />
    <FormTemplate>
        <table cellpadding="2" cellspacing="1" border="0" style="font-size: small; border-collapse: collapse;
            background: white;">
            <tr valign="top">
                <td colspan="2" align="left">
                    <b>Document Details</b>
                </td>
            </tr>
            <tr valign="top">
                <td class="ContentWhite">
                    <span class="Error">*</span>Document Type:
                </td>
                <td class="ContentWhite" align="left">
                    <telerik:RadComboBox ID="rcbDocumentType" runat="server" EnableItemCaching="true" MaxHeight="300px"
                     OnSelectedIndexChanged="rcbDocumentType_SelectedIndexChanged">
                        <Items>
                            <telerik:RadComboBoxItem Value="-Select-" Text="-Select-" />
                            <telerik:RadComboBoxItem Value="1" Text="W9" />
                            <telerik:RadComboBoxItem Value="2" Text="E&O" />
                            <telerik:RadComboBoxItem Value="3" Text="License" />
                            <telerik:RadComboBoxItem Value="4" Text="Vendor Acknowledgement" />
                            <telerik:RadComboBoxItem Value="5" Text="Master Listing Agreement" />
                            <telerik:RadComboBoxItem Value="6" Text="State Registration" />
                        </Items>
                    </telerik:RadComboBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Display="None"
                        ValidationGroup="vgDocument" ControlToValidate="rcbDocumentType" InitialValue="-Select-"
                        ErrorMessage=" Document Type is required " />
                </td>
            </tr>
            <tr valign="top">
                <td class="ContentWhite">
                    <asp:Label ID="lblManagingBrokerFirstName" runat="server" Text="First Name:" Visible="false" />
                </td>
                <td class="ContentWhite" align="left">
                    <telerik:RadTextBox ID="rtbManagingBrokerFirstName" runat="server" MaxLength="128" />
                </td>
            </tr>
            <tr valign="top">
                <td class="ContentWhite">
                    <asp:Label ID="lblManagingBrokerLastName" runat="server" Text="Last Name:" />
                </td>
                <td class="ContentWhite" align="left">
                    <telerik:RadTextBox ID="rtbManagingBrokerLastName" runat="server" MaxLength="128" />
                </td>
            </tr>


How do I toggle the visibility of the radtextbox (rtbManagingBrokerLastName) in the selected index changed event of the combobox (rcbDocumentType)?

3 Answers, 1 is accepted

Sort by
0
Atlas
Top achievements
Rank 1
answered on 03 Aug 2012, 01:06 AM

I figured it out:

protected void rcbDocumentType_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    bool isMasterListingAgreement = e.Value == "5";
    RadComboBox rcbDocumentType = (RadComboBox)sender;
    GridEditFormInsertItem item = (GridEditFormInsertItem)rcbDocumentType.NamingContainer;
 
    Label lblManagingBrokerFirstName = (Label)item.FindControl("lblManagingBrokerFirstName");
    RadTextBox rtbManagingBrokerFirstName = (RadTextBox)item.FindControl("rtbManagingBrokerFirstName");
    Label lblManagingBrokerLastName = (Label)item.FindControl("lblManagingBrokerLastName");
    RadTextBox rtbManagingBrokerLastName = (RadTextBox)item.FindControl("rtbManagingBrokerLastName");
0
Atlas
Top achievements
Rank 1
answered on 03 Aug 2012, 11:20 PM
So I do have an issue. The code above works great when the edit form is in insert mode, but chokes if it is in edit mode. I need to be able to tell from the SelectedIndexChanged event which mode I am in. The code in question is:

var item = (GridEditFormInsertItem)rcbDocumentType.NamingContainer;


How do I change this line of code into an if statement or something so that item correctly corresponds to an Insert Or Edit item depending on which mode I am in?
0
Shinu
Top achievements
Rank 2
answered on 06 Aug 2012, 04:59 AM
Hello,

Try accessing the item in edit mode using GridEditFormItem.
C#:
protected void rcbDocumentType_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
  RadComboBox rcbDocumentType = (RadComboBox)sender;
  GridEditFormItem item = (GridEditFormItem)rcbDocumentType.NamingContainer;
}

Thanks,
Shinu.
Tags
Grid
Asked by
Atlas
Top achievements
Rank 1
Answers by
Atlas
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or