在RadGrid中获取过滤器控件

时间:2013-01-02 17:44:51

标签: c# asp.net telerik telerik-grid

我正在尝试在radgrid上为一个过滤器组合一个组合框。当我尝试以下操作时,我似乎无法找到过滤器控件,没有任何反应。

foreach (GridFilteringItem filterItem in InitAlerts.MasterTableView.GetItems(GridItemType.FilteringItem))
{
    RadComboBox initLoans = (RadComboBox)filterItem.FindControl("InitLoan");

    var loannumber = (from DataRow dRow in initTable.Rows
                        select new { loan_number = dRow["loan_loan_number"] }).Distinct().ToList(); 

    initLoans.DataSource = loannumber;
    initLoans.DataBind();
    Label1.Text = initLoans.ID.ToString();
}

此外,这只是在Page_Load中运行,如果这有所不同......

1 个答案:

答案 0 :(得分:1)

您需要在radgrid的项目数据绑定事件中抓取过滤器

   Protected Sub gvRadGrid_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)
        'filter logic
        If e.Item.ItemType = GridItemType.FilteringItem Then
            Dim filterItem As GridFilteringItem = CType(e.Item, GridFilteringItem)
            Dim cbcombobox As RadComboBox = TryCast(filterItem.FindControl("cbcombobox "), RadComboBox)

cbcombobox .Datasource = 'your datasource'
cbcombobox .databind
        End If

end sub

当然这是用VB编写的,但我确信hyou可以将它转换为C#

这是我通过VB推送到C#转换器的初步转换。它确实很好,但至少它是一个开始。

protected void gvRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    //filter logic
    if (e.Item.ItemType == GridItemType.FilteringItem) {
        GridFilteringItem filterItem = (GridFilteringItem)e.Item;
        RadComboBox cbcombobox = filterItem.FindControl("cbcombobox ") as RadComboBox;

        //your datasource'
        cbcombobox.Datasource = //your datasource
  cbcombobox.databind;
    }

}