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

[Solved] Displaying initial value when bound via AJAX

4 Answers 201 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Skip Harris
Top achievements
Rank 1
Skip Harris asked on 04 May 2012, 04:59 PM
I am trying to use a ComboBox with a remote datasource.  I'm binding to the data source via AJAX.  But when I set my initial value using the Value method it does not show up when the control initially displays.  Only after click on the drop down and the control makes an AJAX call does the selected value display.  Am I missing something here?

@(Html.Telerik().ComboBox()
    .Name("Location")
    .DataBinding(dataBinding =>
        dataBinding.Ajax()
            .Select("AjaxLocationValues", "LocationController")
            )
    .Value(Model.Location)
    )

Thanks,
Skip

4 Answers, 1 is accepted

Sort by
0
Stephen
Top achievements
Rank 1
answered on 11 May 2012, 06:55 AM
I am also hitting this issue.  It doesn't occur on PostBack (that is fine), it occurs when going to a page which has the Telerik ComboBox value bound to a particular value.

I have tried code similar to what Skip has above (except I am using ComboBoxFor).  Setting Value to the integer ID I have does nothing.  I can set Value to the text version of the value but that means that if the user submits something without interacting with the Telerik control the value will be incorrectly set to a string value when it needs to be the appropriate ID.

I have tried using ClientEvents.OnLoad to force the ComboBox to reload but that doesn't seem to do much either.

Any help?
0
Petur Subev
Telerik team
answered on 15 May 2012, 07:33 AM
Hello guys,

The text representation of the value you set is still not retrieved from the server in order to be display. You can force the ComboBox to fetch its collection from the server like so :
e.g. using the OnLoad event:
function onComboLoad()
{
    $(this).data('tComboBox').fill();
}



Regards,
Petur Subev
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Skip Harris
Top achievements
Rank 1
answered on 16 May 2012, 08:24 PM
Petur, thanks for the response.  I hope this limitation will be addressed in a future release.  In my case I have many combo boxes on my page and thousands of possible values for each combo box.  Making a call to the server for each combo box and then returning every possible value is not feasible.  Especially when all I want to do is display the initial value.  Until this limitation is removed the combo box is not usable for me.
0
Thomas
Top achievements
Rank 1
answered on 11 Jul 2012, 03:36 PM
Skip, You can populate the ComboBox on load without additional javascript, but you need access to the text in the Model (or the ViewData):
For this example, assume the model has properties:
int? ItemID
 and
string ItemText

<%:
Html.Telerik()
     .ComboBoxFor(model => model.ItemId)
     .Items(item => 
          item.Add()
               .Text(@Model.ItemText ?? string.Empty)
               .Value(@Model.ItemId.HasValue ? @Model.ItemId.ToString() : string.Empty)
               .Selected(true))
     .DataBinding(dataBinding => dataBinding.Ajax().Select("ActionName", "ControllerName")) %>

Its working for me :-)
Tags
ComboBox
Asked by
Skip Harris
Top achievements
Rank 1
Answers by
Stephen
Top achievements
Rank 1
Petur Subev
Telerik team
Skip Harris
Top achievements
Rank 1
Thomas
Top achievements
Rank 1
Share this question
or