我有DropDownList和Telerik的Kendo UI网格控件的页面.当第一次打开页面时,DropDownList中没有选择任何项目.当用户只在DropDownList中选择值时,Grid应该对服务器进行Ajax调用并加载相应的数据.
当用户在DropDownList中选择项目时,我的代码工作正常,但问题是第一次打开页面时,DropDownList中没有值,Grid不应该调用服务器.
我的问题是,如果在DropDowList中没有选择任何项目,我怎么能阻止网格不调用服务器?
<div> @Html.Kendo().DropDownList().Name("broker").DataTextField("GrandParentName").DataValueField("Id").BindTo(Model).Selectedindex(@selectedindex).Events(e => e.Change("brokerChanged")) </div> @(Html.Kendo().Grid<Orderviewmodel>() .Name("Orders") .HtmlAttributes(new {style = "height: 500"}) .Columns(c => { c.Bound(p => p.Id) .Width(50) .Title("") .sortable(false) .IncludeInMenu(false) .ClientTemplate((@Html.ActionLink("Edit","Index","Splits",new {Id = "OrderId"},null).ToHtmlString().Replace("OrderId","#=Id#"))); c.Bound(p => p.TradeDate) .Title("Trd Dt") .Format("{0:d}") .Width(90) .HtmlAttributes(new {style = "text-align: right"}); c.Bound(p => p.Price) .Title("Price") .Format("{0:n}") .Width(100) .HtmlAttributes(new {style = "text-align: right"}); c.Bound(p => p.Status) .Title("Status"); c.Bound(p => p.Notional) .Title("Notional") .Format("{0:n}") .HtmlAttributes(new {style = "text-align: right"}); }) .sortable() .Scrollable() .ColumnMenu() .Pageable(x => { x.Enabled(true); x.PrevIoUsNext(false); x.PageSizes(false); x.Info(true); x.Input(false); x.Numeric(false); x.Refresh(true); x.Messages(y => y.display("{2} Order(s)")); }) .Resizable(resize => resize.Columns(true)) .Reorderable(reoder => reoder.Columns(true)) .DataSource(ds => ds.Ajax() .ServerOperation(false) .Read(read => read.Action("Action","MyController").Data("selectedbrokerId"))) ) <script type="text/javascript"> function brokerChanged() { var grid = $("#Orders").data("kendoGrid"); grid.dataSource.read(); } function selectedbrokerId() { var obj = { brokerId: $("#broker").data("kendoDropDownList").value() }; return obj; } </script>
非常感谢您的时间和帮助.
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。