Ajaxfied RadGrid RadCombo FilterTemplate

时间:2015-06-27 11:07:51

标签: asp.net telerik telerik-grid radgrid

我想知道如何在RadGrid中实现自定义过滤器。

我有一个Ajaxfied RadGrid,数据源绑定在NeedDatasource事件中。 RadGrid有五列..在那里,我想将其中一个列的过滤器更改为可选过滤器。

所以,我添加了一个FilterTemplate并将RadComboBox添加到其中..

最初,我在设计时自己对所有RadComboBox项进行了硬编码。将javascript绑定到clientside_selectedchanged事件..这种方法运行正常..

当我在后面的代码中将RadComboBox与集合(List)绑定在一起时.. 过滤没有工作..我在GridItemDataBound或GridItemCreated事件中绑定了RadComboBox ..但没有运气..

任何帮助..对我来说都非常有用..我花了差不多两天但我没有任何方向......

自定义过滤器代码 以下是我从项目中复制并粘贴到此处的示例代码。我已经单独更改了字段名称。

过滤模板:

<telerik:GridBoundColumn DataField="DepartmentDescription" Groupable="true" HeaderText="Program" UniqueName="DepartmentDescription">
    <FilterTemplate>
        <telerik:RadComboBox ID="RadComboBoxDepartmentDescription" runat="server"
            AppendDataBoundItems="true"
            DataTextField="DepartDesc"
            DataValueField=" DepartDesc "
            OnClientSelectedIndexChanged=" RadComboBoxDepartmentDescriptionIndexChanged"
            OnDataBound="RadComboBoxAllFilters_OnDataBound"
            SelectedValue='<%# TryCast(Container,GridItem).OwnerTableView.GetColumn("DepartmentDescription ").CurrentFilterValue %>'
            Width="100px">
            <Items>
                <telerik:RadComboBoxItem Text="All" Value="" />
            </Items>
        </telerik:RadComboBox>
        <telerik:RadScriptBlock ID="RadScriptBlockProgram" runat="server">
            <script type="text/javascript">

                function RadComboBoxDepartmentDescriptionIndexChanged(sender, args) {
                    var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID %>");
                    tableView.filter("DepartmentDescription", args.get_item().get_value(), "EqualTo");
                }
            </script> 
        </telerik:RadScriptBlock>
    </FilterTemplate>
    <ItemStyle Wrap="False" />
    <HeaderStyle Wrap="false" />
</telerik:GridBoundColumn>

RadGrid数据绑定代码

protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
(sender as RadGrid).DataSource = employeeList//This is a list of employee of values.. which comes from service layer.. of type .. List<Employee>
}

RadGrid用户界面代码

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <div>
        <telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="true"
            OnNeedDataSource="RadGrid1_NeedDataSource"
..other code I removed it.. like the grid events and bound columns definitions
        </telerik:RadGrid>

RadComboBox在代码背后过滤数据绑定代码:

protected void RadGrid1_ItemDataBound(Object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item Is Telerik.Web.UI.GridFilteringItem)
        {
            'Populate Filters by binding the combo to datasource
            Telerik.Web.UI.GridFilteringItem filteringItem = e.Item as Telerik.Web.UI.GridFilteringItem;
            Telerik.Web.UI.RadComboBox myRadComboBox = filteringItem.FindControl("RadComboBoxDepartmentDescription") as  Telerik.Web.UI.RadComboBox;

            myRadComboBox.DataSource = departmentList; //This is a collection which comes from service layer… and the type is List<Department>
            myRadComboBox.DataTextField = " DepartmentDescription";
            myRadComboBox.DataValueField = " DepartmentDescription";
            myRadComboBox.DataBind();

    }

即使我在ItemCreated事件中粘贴了相同的代码,但也没有运气......

0 个答案:

没有答案