Hi
I have a very strange problem. I have been battling for a while now to create a custom filter for a column which holds a combo of images.
I have centralized the code for my systems grids in a helper class, which is used by all the grid instances system wide. Whats happening is I'm injecting my image filled combo into the GridFilteringItem and my combo is posting back correctly -but- the selectedIndexChanged event is not being raised server side.
I am most certainly binding the event handler on item_created and I'm setting the dynamically created controls id, etc.
The procedure I'm following is basically whats described in the rad grid help file here: ms-help://telerik.radgrid.50.Net2/telerik.radgrid.50.Net2/grdFilteringForChecBoxColumn.html
Code Follows:
(this code lives in the helper class, hence the use of httpContext.current)
The grids are also created via the helper class via the following code:
and
Any ideas?
Thanks,
Anthony.
I have a very strange problem. I have been battling for a while now to create a custom filter for a column which holds a combo of images.
I have centralized the code for my systems grids in a helper class, which is used by all the grid instances system wide. Whats happening is I'm injecting my image filled combo into the GridFilteringItem and my combo is posting back correctly -but- the selectedIndexChanged event is not being raised server side.
I am most certainly binding the event handler on item_created and I'm setting the dynamically created controls id, etc.
The procedure I'm following is basically whats described in the rad grid help file here: ms-help://telerik.radgrid.50.Net2/telerik.radgrid.50.Net2/grdFilteringForChecBoxColumn.html
Code Follows:
(this code lives in the helper class, hence the use of httpContext.current)
| /// <summary> |
| /// Fires when an item was created. |
| /// </summary> |
| /// <param name="sender"></param> |
| /// <param name="e"></param> |
| void _RadGridOnPage_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| if (e.Item.GetType() == typeof(GridEditFormItem)) |
| { |
| SetEditFormCssClass(e.Item.Controls); |
| } |
| //create the custom active col image dropdown filter |
| if (e.Item.GetType() == typeof(GridFilteringItem)) |
| { |
| //create custom filtering dropdown for active col here. |
| GridFilteringItem filteringItem = (e.Item as GridFilteringItem); |
| try |
| { |
| if (filteringItem["clActive"] == null) return; //exit if the active column does not exist |
| } |
| catch |
| { |
| return; //if the col doesnt exist exit. |
| } |
| //append the filtering cbo to the filter header of the col in the grid. |
| filteringItem["clActive"].Controls.Add(CreateActiveColFilterCbo()); //append the new filtering cbo to the filter row |
| if (HttpContext.Current.Session["activeFilterCellClientId"] != null) |
| { |
| HttpContext.Current.Session.Add("activeFilterCellClientId", filteringItem["clActive"].ClientID); |
| } |
| } |
| } |
| /// <summary> |
| /// creates the custom filtering cbo with the tick and cross images. |
| /// </summar |
| private RadComboBox CreateActiveColFilterCbo() |
| { |
| RadComboBox cbo = new RadComboBox(); |
| //create the items to hold the images |
| RadComboBoxItem active = new RadComboBoxItem("Active"); |
| RadComboBoxItem inactive = new RadComboBoxItem("Inactive"); |
| RadComboBoxItem nofilter = new RadComboBoxItem("No Filter"); |
| //create and append the images to the items |
| HtmlImage tick = new HtmlImage(); |
| tick.Src = HttpContext.Current.Request.ApplicationPath + "/images/admin-tick-whitebg.GIF"; |
| HtmlImage cross = new HtmlImage(); |
| cross.Src = HttpContext.Current.Request.ApplicationPath + "/images/admin-cross-whitebg.GIF"; |
| active.Controls.Add(tick); |
| inactive.Controls.Add(cross); |
| //add the items containing the images to the ctl |
| cbo.Items.Add(active); |
| cbo.Items.Add(inactive); |
| cbo.Items.Add(nofilter); |
| cbo.ID = "activeFilterCbo"; |
| cbo.Width = new Unit(65, UnitType.Pixel); |
| cbo.Skin = "WebBlue"; |
| cbo.AutoPostBack = true; |
| cbo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(cbo_SelectedIndexChanged); |
| return cbo; |
| } |
| public void cbo_SelectedIndexChanged(object sender, EventArgs e) |
| { |
| _RadGridOnPage.MasterTableView.Rebind(); |
| } |
| <radG:RadGrid ID="RadGrid1" |
| runat="server"> |
| <MasterTableView > |
| <Columns> |
| <radG:GridTemplateColumn UniqueName="clActive" AllowFiltering=false> |
| <ItemTemplate> |
| <asp:Image ID="imgActive" |
| runat="server" /> |
| <asp:Label ID="lblActive" |
| runat="server" |
| Text='<%# DataBinder.Eval(Container,"DataItem." + comQuest.Common.Constants.Columns.USR_Active) %>' |
| style="display: none"></asp:Label> |
| </ItemTemplate> |
| </radG:GridTemplateColumn> |
| </Columns> |
| <ExpandCollapseColumn Visible="False" Resizable="False"> |
| <HeaderStyle Width="20px" /> |
| </ExpandCollapseColumn> |
| <RowIndicatorColumn Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </RowIndicatorColumn> |
| </MasterTableView> |
| <ExportSettings> |
| <Pdf PageBottomMargin="" PageFooterMargin="" PageHeaderMargin="" PageHeight="11in" |
| PageLeftMargin="" PageRightMargin="" PageTopMargin="" PageWidth="8.5in" /> |
| </ExportSettings> |
| </radG:RadGrid> |
The grids are also created via the helper class via the following code:
| /// <summary> |
| /// Sets up the databound cols and other grid properties |
| /// </summary> |
| public void CreateGrid(bool enableAjax, Dictionary<string, bool> ColumnsFilterStatus) |
| { |
| //create the grid |
| _RadGridOnPage.CssClass = "RadGrid"; |
| //_RadGridOnPage.PageSize = 5; |
| _RadGridOnPage.AllowPaging = true; |
| _RadGridOnPage.AutoGenerateColumns = false; |
| _RadGridOnPage.Visible = true; |
| _RadGridOnPage.Width = new Unit(98, UnitType.Percentage); |
| _RadGridOnPage.MasterTableView.EditMode = GridEditMode.EditForms; |
| _RadGridOnPage.Skin = "WebBlue"; |
| _RadGridOnPage.MasterTableView.PageSize = 20; |
| _RadGridOnPage.MasterTableView.AutoGenerateColumns = false; |
| _RadGridOnPage.HeaderStyle.Font.Size = new FontUnit("8pt"); |
| if (enableAjax) |
| { |
| _RadGridOnPage.LoadingTemplateTransparency = 50; |
| _RadGridOnPage.ShowGroupPanel = true; |
| _RadGridOnPage.ClientSettings.AllowDragToGroup = true; |
| _RadGridOnPage.AllowFilteringByColumn = true; |
| _RadGridOnPage.EnableAJAX = true; |
| _RadGridOnPage.EnableAJAXLoadingTemplate = true; |
| } |
| _RadGridOnPage.AllowSorting = true; |
| //_RadGridOnPage.AllowFilteringByColumn = true; |
| _RadGridOnPage.PagerStyle.CssClass = "gridpager"; |
| _RadGridOnPage.PagerStyle.Mode = GridPagerMode.NumericPages; |
| //setup the add new entry at the top of the grid |
| if (_EnableRecordAdd) |
| { |
| _RadGridOnPage.MasterTableView.CommandItemSettings.AddNewRecordText = _AddNewRecordText; |
| _RadGridOnPage.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top; |
| } |
| else |
| { |
| _RadGridOnPage.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None; |
| } |
| // Set data source. |
| _RadGridOnPage.DataSource = _MainDataSet; |
| _RadGridOnPage.DataMember = _DataTableNameAsDatasource; // The datatable to be the datasource |
| //add grid cols |
| AddGridCols(_RadGridOnPage.MasterTableView, ColumnsFilterStatus); |
| if (EnableSimpleDetailView) |
| { |
| if (_RadGridOnPage.MasterTableView.DetailTables.Count > 0) |
| { |
| AddGridCols(_RadGridOnPage.MasterTableView.DetailTables[0], ColumnsFilterStatus); |
| } |
| } |
| _RadGridOnPage.DataSource = _MainDataSet; |
| _RadGridOnPage.DataBind(); |
| // Add the edit column |
| if (_EnableRecordEdit) |
| { |
| GridEditCommandColumn editCol = new GridEditCommandColumn(); |
| _RadGridOnPage.MasterTableView.Columns.Add(editCol); |
| editCol.EditText = comQuest.Resources.Resources.GetMessage("RES_Grid_EditColumnEditText"); |
| editCol.OrderIndex = _MainDataSet.Tables[_DataTableNameAsDatasource].Columns.Count + 2; |
| } |
| // Add the delete column |
| if (_EnableRecordDelete) |
| { |
| GridButtonColumn butCol = new GridButtonColumn(); |
| _RadGridOnPage.MasterTableView.Columns.Add(butCol); |
| butCol.CommandName = "Delete"; |
| butCol.Text = comQuest.Resources.Resources.GetMessage("RES_Grid_DeleteColumnDeleteText"); |
| butCol.UniqueName = "DeleteColumn"; |
| butCol.OrderIndex = _MainDataSet.Tables[_DataTableNameAsDatasource].Columns.Count + 3; |
| butCol.ConfirmText = comQuest.Resources.Resources.GetMessage("RES_GridDeleteConfirmationMessage"); |
| } |
| //format design time columns |
| FormatActiveColumn(_RadGridOnPage.MasterTableView); |
| if (EnableSimpleDetailView) |
| { |
| if (_RadGridOnPage.MasterTableView.DetailTables.Count > 0) |
| { |
| FormatActiveColumn(_RadGridOnPage.MasterTableView.DetailTables[0]); |
| } |
| } |
| // Set colours |
| SetColours(); |
| // Prevent from jumping to last page after insert |
| _RadGridOnPage.ItemCommand += new GridCommandEventHandler(_RadGridOnPage_ItemCommand); |
| } |
and
| void ToDoOnNew() |
| { |
| // This event handlers needs to build every time. On load and postback. |
| _RadGridOnPage.NeedDataSource += new GridNeedDataSourceEventHandler(_RadGridOnPage_NeedDataSource); |
| _RadGridOnPage.ItemDataBound += new GridItemEventHandler(_RadGridOnPage_ItemDataBound); |
| _RadGridOnPage.UpdateCommand += new GridCommandEventHandler(_RadGridOnPage_UpdateCommand); |
| _RadGridOnPage.InsertCommand += new GridCommandEventHandler(_RadGridOnPage_InsertCommand); |
| _RadGridOnPage.DeleteCommand += new GridCommandEventHandler(_RadGridOnPage_DeleteCommand); |
| _RadGridOnPage.DetailTableDataBind += new GridDetailTableDataBindEventHandler(_RadGridOnPage_DetailTableDataBind); |
| _RadGridOnPage.ItemCreated += new GridItemEventHandler(_RadGridOnPage_ItemCreated); |
| _RadGridOnPage.Load += new EventHandler(_RadGridOnPage_Load); |
| // Make sure all the lists are new and not null. |
| if (_ColumnsToExclude == null) _ColumnsToExclude = new List<string>(); |
| if (_DropdownColumns == null) _DropdownColumns = new List<RadGridHelperDropdownColumn>(); |
| if (_GuidBeingEdited == null) _GuidBeingEdited = new Dictionary<string, Guid>(); |
| if (_ReadOnlyColumnNames == null) _ReadOnlyColumnNames = new List<string>(); |
| } |
Any ideas?
Thanks,
Anthony.