我想知道如何在RadGrid中实现自定义过滤器 .
我有一个Ajaxfied RadGrid,数据源绑定在NeedDatasource事件中 . RadGrid有五列..在那里,我想将其中一列的过滤器更改为可选择的过滤器 .
所以,我添加了一个FilterTemplate并将RadComboBox添加到其中 .
最初,我在设计时自己硬编码了所有的RadComboBox项目 . 将javascript加入到clientside_selectedchanged事件中..这种方法工作正常..
当我在后面的代码中将RadComboBox与集合(List)绑定在一起时..过滤不起作用..我在GridItemDataBound或GridItemCreated事件中绑定了RadComboBox ..但没有运气..
任何帮助..对我来说都非常有用..我花了近两天但我没有任何方向......
Custom Filter Code 以下是我从项目中复制并粘贴到此处的示例代码..我已经单独更改了字段名称..
Filter Template:
<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 DataBinding Code
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 UI Code
<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 Filter DataBinding Code in the Code Behind:
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事件中粘贴了相同的代码,但没有运气......