我需要在下拉选择更改中更改telerik mvc网格数据源。下面是我当前的视图,我想用下拉选项更改网格。
<%@ Page Title="" Language="C#" MasterPageFile="~/ViewMasterPage.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<GateApplication.Models.Gate>>" %>
<%@ Import Namespace="Telerik.Web.Mvc.UI" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div align="left" style="width: 100%">
<table><tr>
<td>Search Form: </td>
<td><%= Html.Telerik().DropDownListFor(model => ViewData["drpSearch"])
.HtmlAttributes(new { @Style="width:250px" })
.BindTo(new SelectList((List<SelectListItem>)ViewData["drpSearch"], "Text", "Value"))%></td>
</tr></table>
</div>
<br />
<%= Html.Telerik().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.ID).Visible(false);
columns.Bound(o => o.Urgency);
columns.Bound(o => o.FullName);
columns.Bound(o => o.Email);
columns.Bound(o => o.GateSupportedBy);
columns.Bound(o => o.FullPhone1).Title("Phone Number");
columns.Bound(o => o.StNstNo).Title("St. and St. No.");
})
.DataBinding(dataBinding =>
{
dataBinding.Ajax().Select("AjaxGrid",
"Gate").Enabled(true);
})
.Scrollable(scrolling => scrolling.Enabled(true))
.Sortable(sorting => sorting.Enabled(true))
.Pageable(paging => paging.Enabled(true).PageSize(10))
.Filterable(filtering => filtering.Enabled(true))
.Groupable(grouping => grouping.Enabled(true))
.Footer(true)
%>
</asp:Content>
答案 0 :(得分:0)
关于下拉列表更改事件
$("#drpSearch").change(function(){
if(this.value =="your condition"){
//you can try using rebind
var grid = $("#Grid").data("tGrid");
//send additional arguments by passing them as a literal JavaScript object
grid.rebind({DataFromOtherSource : true});
}
});
在您的方法中,您可以返回不同的数据集。
答案 1 :(得分:-1)
您应该考虑在运行时更改 datasource select命令。
让我们举例说:
myDatasource.selectcommand="SELECT Username FROM tblUsers"
GridView1.DataBind()