0

我需要在下拉选择更改时更改 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>
4

2 回答 2

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});
    }
});

在您的方法中,您可以返回不同的数据集。

于 2013-05-27T00:22:20.967 回答
-1

您应该考虑在运行时更改数据源选择命令。

比如说:

myDatasource.selectcommand="SELECT Username FROM tblUsers"
GridView1.DataBind()
于 2013-05-25T14:23:19.327 回答