Hello All,
I have created filter with multiple check boxs using RadComboBox in RadGrid. Its working fine but the problem is when I apply filter it rebinds datasource and all the check boxes are set to checked again, and I am loosing the applied filtered values. \
Also I want to change EmptyMessage and RadComboBox errow icon, if possible.
Admin please look into this.
Thank you!
Vishal
I have created filter with multiple check boxs using RadComboBox in RadGrid. Its working fine but the problem is when I apply filter it rebinds datasource and all the check boxes are set to checked again, and I am loosing the applied filtered values. \
Also I want to change EmptyMessage and RadComboBox errow icon, if possible.
Admin please look into this.
Thank you!
Vishal
2 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 04 Jul 2014, 05:34 AM
Hi Vishal,
I'm not clear about the issue, please take a look at the sample code snippet and if this doesn't help, provide your full code snippet. To set empty message RadComboBox has a property EmptyMessage , then I'm not sure what you mean by error icon, please elaborate.
ASPX:
C#:
Thanks,
Shinu
I'm not clear about the issue, please take a look at the sample code snippet and if this doesn't help, provide your full code snippet. To set empty message RadComboBox has a property EmptyMessage , then I'm not sure what you mean by error icon, please elaborate.
ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1" OnAjaxRequest="RadAjaxManager1_AjaxRequest"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="clrFilters"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings></telerik:RadAjaxManager><telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default" /><telerik:RadGrid ID="RadGrid1" runat="server" OnPreRender="RadGrid1_PreRender" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource" EnableLinqExpressions="false"> <MasterTableView EditMode="InPlace" AllowFilteringByColumn="true" CommandItemDisplay="Top"> <Columns> <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" SortExpression="EmployeeID" UniqueName="EmployeeID" DataType="System.Int32"> <FilterTemplate> <telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource1" DataValueField="EmployeeID" DataTextField="EmployeeID" EmptyMessage="Filter Text" AllowCustomText="true" Width="240px"> <ItemTemplate> <asp:CheckBox runat="server" Checked="true" ID="chk1" onclick="onCheckBoxClick(this)" /> <%# Eval("EmployeeID")%> </ItemTemplate> </telerik:RadComboBox> <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"> <script type="text/javascript"> function onCheckBoxClick(chk) { var text = "", values = ""; var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>"); var combo = $find('<%# ((GridItem)Container).FindControl("RadComboBox1").ClientID %>'); //get the collection of all items var items = combo.get_items(); //enumerate all items for (var i = 0; i < items.get_count(); i++) { var item = items.getItem(i); //get the checkbox element of the current item var chk1 = $get(combo.get_id() + "_i" + i + "_chk1"); if (chk1.checked) { text += item.get_text() + ","; values += item.get_value() + ","; } } //remove the last comma from the string text = removeLastComma(text); values = removeLastComma(values); $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("EmployeeID," + text); } function removeLastComma(str) { return str.replace(/,$/, ""); } </script> </telerik:RadScriptBlock> </FilterTemplate> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="LastName" AllowFiltering="true" HeaderText="LastName" SortExpression="LastName" UniqueName="LastName"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" UniqueName="FirstName"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="HireDate" HeaderText="HireDate" SortExpression="HireDate" UniqueName="HireDate" DataType="System.DateTime" DataFormatString="{0:D}"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="City" HeaderText="City" SortExpression="City" UniqueName="City"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Country" HeaderText="Country" SortExpression="Country" UniqueName="Country"> </telerik:GridBoundColumn> </Columns> </MasterTableView> <ClientSettings> <Selecting AllowRowSelect="true" /> </ClientSettings></telerik:RadGrid><br /><asp:Button ID="clrFilters" runat="server" Text="Clear filters" OnClick="clrFilters_Click" />C#:
protected void Page_Load(object sender, EventArgs e){ ViewState["filterRawString"] = null;}protected void RadGrid1_PreRender(object sender, EventArgs e){ if (ViewState["filterRawString"] != null) { foreach (GridFilteringItem item in RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)) { RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1"); foreach (RadComboBoxItem comboItem in combo.Items) { if (ViewState["filterRawString"].ToString().Contains(comboItem.Text.ToString())) { CheckBox chk = (CheckBox)comboItem.FindControl("chk1"); chk.Checked = true; } else { CheckBox chk = (CheckBox)comboItem.FindControl("chk1"); chk.Checked = false; } } } }}protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e){ string str = e.Argument.ToString(); String query = "SELECT EmployeeID, FirstName, LastName, HireDate, City, Country FROM Employees WHERE EmployeeID = '" + str.Split(',')[1] + "'"; if (str.Split(',')[0] == "EmployeeID") { for (int i = 2; i < str.Split(',').Length; i++) { query = query + " OR EmployeeID='" + str.Split(',')[i] + "'"; } ViewState["filterRawString"] = str; RadGrid1.DataSource = GetDataTable(query); RadGrid1.Rebind(); GridFilteringItem filterItem = RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem; RadComboBox combo = (RadComboBox)filterItem.FindControl("RadComboBox1"); RadAjaxManager1.ResponseScripts.Add("$find('" + combo.ClientID + "').showDropDown();"); }} protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e){ if (ViewState["filterRawString"] == null) RadGrid1.DataSource = GetDataTable("SELECT EmployeeID, FirstName, LastName, HireDate, City, Country FROM Employees");}protected void clrFilters_Click(object sender, EventArgs e){ foreach (GridColumn column in RadGrid1.MasterTableView.Columns) { column.CurrentFilterFunction = GridKnownFunction.NoFilter; column.CurrentFilterValue = string.Empty; } RadGrid1.MasterTableView.FilterExpression = string.Empty; RadGrid1.MasterTableView.Rebind();}public DataTable GetDataTable(string query){ String ConnString = ConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString; SqlConnection conn = new SqlConnection(ConnString); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = new SqlCommand(query, conn); DataTable myDataTable = new DataTable(); conn.Open(); try { adapter.Fill(myDataTable); } finally { conn.Close(); } return myDataTable;}Thanks,
Shinu
0
vishal
Top achievements
Rank 1
answered on 04 Jul 2014, 12:29 PM
Sorry, for not mentioning the issue clearing, but thanks Shinu, your explanation helped me a lot and my issues has been resolved.
Thanks again.
Vishal
Thanks again.
Vishal