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

Is there a Bind event?

1 Answer 131 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 17 Apr 2017, 05:28 PM

I have a DropdownList on my page. I have it set as follows:

@(Html.Kendo().DropDownListFor(m => m)
                        .Name("CustomerDropDown")
                        .DataTextField("DropDownText")
                        .DataValueField("RowId")
                        .OptionLabel("Select Customer or Reseller...")
                        .AutoBind(true)
                        .Filter("contains")
                        .HtmlAttributes(new { style = "width:500px" })
                        .DataSource(source =>
                        {
                            source.Read(read =>
                            {
                                read.Action("GetCustomersForPointofSaleDropDown", "Customer");
                            })
                            .ServerFiltering(true);
                        })
                        .Events(e =>
                        {
                            e.Select("onCustomerSelect").DataBound("onDropDownListBound");
                        })
                    )

Under certain circumstances I don't want the drop down list to auto bind. I don't see a Bind event I can latch on to, like I can with the data bound event, in order for me to prevent the binding from happening. Is there some way I can prevent the auto binding before it actually occurs?

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 18 Apr 2017, 11:10 AM
Hello Randy,

Thank you for the example provided and the additional clarifications of the issue.

Currently there is no DataBinding event, with which would allow you to prevent the binding from happening. However, you can check the two solutions below, which might help you to achieve the desired result.

In the attached file (TelerikMvcAppDropDownList.zip) you will find a simple implementation of the Kendo DropDownList, which prevents the DataSource binding on RequestStart event of the DataSource. The HTML and the JS code to achieve this can be found in Views/Home/Index.cshtml. You will notice that I have added an event handler to the DataSource property and I have executed some custom JS code to stop the request and disable to loading icon:
e.preventDefault();
setTimeout(
function () {

  $(
'.k-icon').removeClass('k-i-loading');

}, 200);

I have also added a "Turn bindings ON" button, which enables the binding of the DataSource.

Another way to prevent the auto binding would be to manually bind the DropDownList widget with JS only when you need to. For more detailed example you can check the following demo.

If you have any other questions, please do not hesitate to contact us.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
DropDownList
Asked by
Randy
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or