I'm trying to set up custom filtering in the radgrid. I've read through the documentation and the examples and have had a hard time piecing them together. Each example seems to have different code and I can't really comprehend them or get them to work.
What I want it to look like is:
http://www.telerik.com/demos/aspnet/Grid/Examples/Programming/FilteringTemplateColumns/DefaultCS.aspx but this code has no c# or vb code, so it's not very usable.
I found this simple example in one of the forum threads, and it works well in displaying the dropdown list with the data populated, however I cannot get the combo_SelectedIndexChanged event to fire.
Here's the applicable code behind:
Here is the aspx code for the grid:
Please note I have the "allowfiltering=false" set in the "loc" column to prevent the viewstate errors that occur when manually adding a filter control. Also, this grid is ajax-enabled, do I need to somehow add the combo box control to the ajax events? If so, how would I do that.
Am I missing something else to get this code to work? Or is it impossible to have custom filters without using that MyCustomFilteringColumn class. And if I must use that class, can someone please provide a thorough example along the lines of what I have up there, with kind of an explanation? I would really appreciate it.
It's been kind of frustrating trying to wade through all the disparate documentation to get a working product. I would appreciate some direction.
Thanks!
-Angie
What I want it to look like is:
http://www.telerik.com/demos/aspnet/Grid/Examples/Programming/FilteringTemplateColumns/DefaultCS.aspx but this code has no c# or vb code, so it's not very usable.
I found this simple example in one of the forum threads, and it works well in displaying the dropdown list with the data populated, however I cannot get the combo_SelectedIndexChanged event to fire.
Here's the applicable code behind:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
{ |
if (e.Item is GridFilteringItem) |
{ |
GridFilteringItem item = (GridFilteringItem)e.Item; |
item["loc"].Controls.Clear(); |
RadComboBox combo = new RadComboBox(); |
combo.ID = "RadComboBox1"; |
combo.Items.Add(new RadComboBoxItem("", "")); |
combo.Items.Add(new RadComboBoxItem("Main Page", "1")); |
combo.Items.Add(new RadComboBoxItem("Left Nav", "2")); |
combo.AutoPostBack = true; |
combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(combo_SelectedIndexChanged); |
item["loc"].Controls.Add(combo); |
//RadAjaxManager1.AjaxSettings.AddAjaxSetting(combo,RadGrid1); |
} |
} |
void combo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) |
{ |
RadComboBox combo = (RadComboBox)sender; |
RadGrid1.MasterTableView.FilterExpression = "([loc_id] = '" + combo.SelectedValue + "') "; |
GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("loc"); |
column.CurrentFilterFunction = GridKnownFunction.EqualTo; |
RadGrid1.Rebind(); |
} |
Here is the aspx code for the grid:
<telerik:RadAjaxManager EnableAJAX="true" ID="RadAjaxManager1" runat="server"> |
<AjaxSettings> |
<telerik:AjaxSetting AjaxControlID="RadGrid1"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="Button1"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
</AjaxSettings> |
</telerik:RadAjaxManager> |
<telerik:RadGrid ID="RadGrid1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound" |
AllowFilteringByColumn="True" AllowSorting="True" |
GridLines="None" Skin="Office2007" Width="400px" |
OnNeedDataSource="RadGrid1_NeedDataSource" |
OnUpdateCommand="RadGrid1_UpdateCommand" OnInsertCommand="RadGrid1_InsertCommand" |
OnItemCommand="RadGrid1_ItemCommand" |
> |
<MasterTableView autogeneratecolumns="False" AllowFilteringByColumn="True" commanditemdisplay="Top" editmode="InPlace" DataKeyNames="zone_id" > |
<RowIndicatorColumn Visible="False"> |
<HeaderStyle Width="20px"></HeaderStyle> |
</RowIndicatorColumn> |
<ExpandCollapseColumn Visible="False" Resizable="False"> |
<HeaderStyle Width="20px"></HeaderStyle> |
</ExpandCollapseColumn> |
<Columns> |
<telerik:GridEditCommandColumn> |
</telerik:GridEditCommandColumn> |
<telerik:GridCheckBoxColumn DataField="status" DataType="System.Boolean" ItemStyle-HorizontalAlign="Center" |
HeaderText="status" SortExpression="status" UniqueName="status" > |
<ItemStyle HorizontalAlign="Center"></ItemStyle> |
</telerik:GridCheckBoxColumn> |
<telerik:GridBoundColumn DataField="order_by" DataType="System.Int32" ItemStyle-Width="30px" |
HeaderText="order_by" SortExpression="order_by" UniqueName="order_by" |
AllowFiltering="False"> |
<ItemStyle Width="30px"></ItemStyle> |
</telerik:GridBoundColumn> |
<telerik:GridTemplateColumn HeaderText="Category Name" |
SortExpression="category_name" UniqueName="category_name" |
AllowFiltering="False" > |
<ItemTemplate> |
<asp:Label runat="server" ID="lbCategory" Text='<%#Eval("category_name") %>' /> |
</ItemTemplate> |
<EditItemTemplate> |
<asp:DropDownList ID="ddlCategory" runat="server" Width="150px" /> |
</EditItemTemplate> |
</telerik:GridTemplateColumn> |
<telerik:GridBoundColumn DataField="zone_id" DataType="System.Int32" |
HeaderText="zone_id" ReadOnly="True" SortExpression="zone_id" |
UniqueName="zone_id" Display="false" > |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="loc_id" DataType="System.Int32" |
HeaderText="loc_id" SortExpression="loc_id" UniqueName="loc_id" Display="false" > |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="loc" HeaderText="loc" ItemStyle-Width="60px" |
SortExpression="loc" UniqueName="loc" ReadOnly="True" AllowFiltering="False"> |
<ItemStyle Width="60px"></ItemStyle> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="id_type" HeaderText="id_type" ItemStyle-Width="60px" |
SortExpression="id_type" UniqueName="id_type" ReadOnly="true"> |
<ItemStyle Width="60px"></ItemStyle> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="category_id" DataType="System.Int32" |
HeaderText="category_id" SortExpression="category_id" UniqueName="category_id" |
Display="false"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="site_name" HeaderText="site_name" ReadOnly="true" |
SortExpression="site_name" UniqueName="site_name"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="site_id" DataType="System.Int32" |
HeaderText="site_id" SortExpression="site_id" UniqueName="site_id" |
Visible="False"> |
</telerik:GridBoundColumn> |
</Columns> |
<EditFormSettings EditFormType="WebUserControl" UserControlName="AdminUC/BannerZoneInsert.ascx"> |
<EditColumn UniqueName="EditCommandColumn1"></EditColumn> |
<PopUpSettings ScrollBars="None"></PopUpSettings> |
</EditFormSettings> |
</MasterTableView> |
</telerik:RadGrid> |
Please note I have the "allowfiltering=false" set in the "loc" column to prevent the viewstate errors that occur when manually adding a filter control. Also, this grid is ajax-enabled, do I need to somehow add the combo box control to the ajax events? If so, how would I do that.
Am I missing something else to get this code to work? Or is it impossible to have custom filters without using that MyCustomFilteringColumn class. And if I must use that class, can someone please provide a thorough example along the lines of what I have up there, with kind of an explanation? I would really appreciate it.
It's been kind of frustrating trying to wade through all the disparate documentation to get a working product. I would appreciate some direction.
Thanks!
-Angie