Reputation: 335
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...
Upvotes: 1
Views: 4526
Reputation: 1364
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;
}
}
Upvotes: 1