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

Databound values not saving when set via Javascript

2 Answers 65 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 21 May 2012, 02:02 PM
I have the following ASPX page:

<script type="text/javascript">
    function SectorChanged(sender, eventArgs) {
        var selectedItem = eventArgs.get_item();
        var selectedItemText = selectedItem.get_element().childNodes[1].innerText;
 
        var textInput = $get('<%= companyGicsFormView.FindControl("txtSectorText").ClientID %>');
        textInput .value = selectedItemText ;
        textInput .text = selectedItemText ;
    }
 
    function OnClientDropDownOpeningHandler(sender, eventArgs) {
        sender.requestItems("", false);
    }
</script>
 
<asp:FormView runat="server" ID="formView" DefaultMode="Edit">
  <EditItemTemplate>
    <telerik:RadComboBox runat="server" ID="cboTest" DataSourceID="customDs"
                                             DataTextField="Sector" DataValueField="Sector" SelectedValue='<%# Bind("Sector") %>'
                                             OnClientSelectedIndexChanged="SectorChanged"
                                             HighlightTemplatedItems="true" AllowCustomText="false" EnableLoadOnDemand="false"
                                             OnClientDropDownOpening="OnClientDropDownOpeningHandler">
                        <ItemTemplate>
                                <%# DataBinder.Eval(Container.DataItem, "Sector") %>
                                <span style="display:none;"><%# DataBinder.Eval(Container.DataItem, "SectorText")%></span>
                        </ItemTemplate>
    </telerik:RadComboBox>
    <telerik:RadTextBox ID="txtSectorText" runat="server" Text='<%# Bind("SectorText") %>' MaxLength="255" ReadOnly="False" Enabled="False" />
  </EditItemTemplate>
</asp:FormView>

The cboTest Combo Box is being populated correctly. The txtSectorText is also updated when I select something from the combobox. However: Neither the combo box value nor the textbox value are saved to the datasource.

I'm thinking this has something to do with databinding, but I'm stuck on how to correctly databind these two controls.

(PS: What I'm basically trying to do is to set the textbox value based upon a selection from the combo box)

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivana
Telerik team
answered on 22 May 2012, 02:24 PM
Hello Dennis,

Take a look at the following forum discussing how the button events of FormView should be handled when inserting, updating, or deleting data: http://forums.asp.net/t/1079602.aspx/1.

Greetings,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Dennis
Top achievements
Rank 1
answered on 23 May 2012, 09:50 AM
Perfect. Thank you!
Tags
ComboBox
Asked by
Dennis
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Dennis
Top achievements
Rank 1
Share this question
or