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

RadComboBox inside FormView inside User Control - formview disappears after edit

1 Answer 104 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Kevin F
Top achievements
Rank 1
Kevin F asked on 23 Jul 2013, 12:23 AM
I've spent half the day searching for a solution to this but I just can't get it.

I have a TabStrip which is loaded on demand (each tab has its own user control).  On this particular one, I am loading a form view.  The Edit and Insert templates on the formview are identical (except for the command buttons).  Here is the EditItemTemplate.

<EditItemTemplate>
    <div class="formLine">
        <div class="formField66">
            Name of Employer:
            <telerik:RadTextBox ID="txtEmployerName" runat="server" MaxLength="50" Width="400" Text='<%# Bind("Name") %>'></telerik:RadTextBox>
        </div>
    </div>
    <div class="formLine">
        <div class="formField66">
            Employment Address:
            <telerik:RadTextBox ID="txtEmployerAddress" runat="server" MaxLength="50" Width="400" Text='<%# Bind("Address") %>'></telerik:RadTextBox>
        </div>
    </div>
    <div class="formLine">
        <div class="formField33">
            City, State:
            <asp:LinkButton ID="lnkAddEmploymentCity" runat="server" OnClick="lnkAddEmploymentCity_Click">ADD CITY</asp:LinkButton>
            <br />
            <telerik:RadComboBox ID="cboEmploymentCity" runat="server" EmptyMessage="Type city ..." DataSourceID="dsCities" DataValueField="IDNumber" DataTextField="CITY"
                MarkFirstMatch="true" DropDownAutoWidth="Enabled">
                <ItemTemplate>
                    <%# Eval("CITY") %>, <%# Eval("State") %>, <%# Eval("ZIPCODE1") %>  <%# Eval("COUNTY") %>
                </ItemTemplate>
            </telerik:RadComboBox>
            ,
            <telerik:RadTextBox ID="txtEmploymentState" runat="server" MaxLength="2" Width="45px" Enabled="false" Text='<%# Bind("State") %>'></telerik:RadTextBox>
        </div>
        <div class="formField33">
            County:<br />
            <telerik:RadTextBox ID="txtEmploymentCounty" runat="server" MaxLength="50" Enabled="false" Text='<%# Bind("County") %>'></telerik:RadTextBox>
        </div>
        <div class="formField33">
            Zip:<br />
            <telerik:RadMaskedTextBox ID="txtEmploymentZip" runat="server" Mask="#####" Enabled="false" Text='<%# Bind("ZipCode") %>'></telerik:RadMaskedTextBox>
        </div>
    </div>
    <div class="formLine">
        <div class="formField33">
            Phone Number:<br />
            <telerik:RadMaskedTextBox ID="txtEmploymentPhoneNumber" runat="server" Mask="(###) ###-####" Columns="15" Text='<%# Bind("Phone") %>'></telerik:RadMaskedTextBox>
        </div>
        <div class="formField66">
            Employment Begin Date:
            <telerik:RadDatePicker ID="txtEmploymentStartDate" runat="server" MinDate="1/1/1900" SelectedDate='<%# Bind("BeginDate") %>'></telerik:RadDatePicker>
        </div>
    </div>
    <div class="formLine">
        <div class="formField66">
            Occupation:
            <telerik:RadTextBox ID="txtEmploymentOccupation" runat="server" MaxLength="255" Width="400" Text='<%# Bind("Occupation") %>'></telerik:RadTextBox>
        </div>
    </div>
    <asp:Button runat="server" Text="Update this Record" CommandName="Update" ID="UpdateButton" CausesValidation="True" />
    <asp:Button runat="server" Text="Cancel Edit" CommandName="Cancel" ID="UpdateCancelButton" CausesValidation="False" />
</EditItemTemplate>

In the FormView's ItemCreated event I set the RadCombo box to AutoPostback and also attach the SelectedIndexChanged event handler:
protected void frmEmployment_ItemCreated(object sender, EventArgs e)
{
    RadComboBox cbo = (RadComboBox)frmEmployment.FindControl("cboEmploymentCity");
    if (cbo != null)
    {
        cbo.AutoPostBack = true;
        cbo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(cboEmploymentCity_SelectedIndexChanged);
    }
}
 
protected void cboEmploymentCity_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    RadTextBox txtEmploymentCounty = frmEmployment.FindControl("txtEmploymentCounty") as RadTextBox;
    RadTextBox txtEmploymentState = frmEmployment.FindControl("txtEmploymentState") as RadTextBox;
    RadMaskedTextBox txtEmploymentZip = frmEmployment.FindControl("txtEmploymentZip") as RadMaskedTextBox;
    int addressId = 0;
    if (Int32.TryParse(e.Value, out addressId))
    {
        var addressInfo =
            (from z in db.ZipCodes where z.IDNumber == addressId select z).SingleOrDefault();
        txtEmploymentCounty.Text = addressInfo.COUNTY;
        txtEmploymentState.Text = addressInfo.State;
        txtEmploymentZip.Text = addressInfo.ZIPCODE1;
    }
    else
    {
        txtEmploymentCounty.Text = string.Empty;
        txtEmploymentState.Text = string.Empty;
        txtEmploymentZip.Text = string.Empty;
    }
}

The idea: the user selects a city from the RadComboBox, and in turn the State, Zip, and County RadTextBoxes are updated with data from the database.

The major frustration here is that it works fine when I dealing with a new record.  When I enter Edit mode on the FormView, and change the index of the RadComboBox, the whole FormView disappears from view, but seems to be stuck in Edit mode.

I've pulled the Ajax from the user control.  There is, however, a RadAjaxManager on the parent page which I use to allow the tab strip and the page views to update each other.

Any help is greatly appreciated!

1 Answer, 1 is accepted

Sort by
0
Kevin F
Top achievements
Rank 1
answered on 23 Jul 2013, 06:33 PM
Update - I changed it use RadListView instead of a FormView and it works perfectly for Insert and Update.
Tags
ComboBox
Asked by
Kevin F
Top achievements
Rank 1
Answers by
Kevin F
Top achievements
Rank 1
Share this question
or