简体   繁体   中英

Getting the filter control in a RadGrid

I'm trying to databind a combobox for a filter on a radgrid . I can't seem to be able to find the filter control when i try the following, nothing happens.

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

Also, this is just running in Page_Load , if that makes a difference...

You need to grab the filter in the item databound event of a 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

Of course this was written in VB but I'm sure hyou can convert it to C#

Here's a preliminary conversion that I pushed through a VB to C# converter. It doens' talways play nice but at least it's a start.

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM