This is a migrated thread and some comments may be shown as answers.

Problem with filtering the Radgird.

3 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jessy Joseph
Top achievements
Rank 1
Jessy Joseph asked on 15 Apr 2011, 09:40 PM
I have a grid with three columns and I want user to enter their filter values and then click "Search Filter" button which is outside the grid.
Two columns have a textboxes for filter and the last column has a combobox with checkbox in it.
Everything works fine when the textbox columns are filtered. Problem occurs when the combobox with checkbox is selected.  it returns no data found. You  can see the image attached and also Client and Serverside codes.

Do let me know where am I going wrong...Any help will be appreciated.

Thanks

ASPX
<telerik:RadGrid ID="rgPartnerPhone" runat="server" AllowFilteringByColumn="True"
   AllowPaging="True" AllowSorting="True" DataSourceID="dsPartnerPhone" GridLines="None"
Skin="Outlook" Width="100%" ShowGroupPanel="True" AutoGenerateColumns="False"
 PageSize="50" Height="570px" OnItemCreated="rgPartnerPhone_ItemCreated" OnPreRender="rgPartnerPhone_PreRender"
 ShowFooter="true">
 <MasterTableView DataSourceID="dsPartnerPhone" DataKeyNames="ProductID,  ProductName"
PageSize="50" Width="100%" GroupLoadMode="Client" EnableNoRecordsTemplate="true"
ShowHeadersWhenNoRecords="true" AllowFilteringByColumn="true" AllowMultiColumnSorting="true"
EnableHeaderContextMenu="true">
<NoRecordsTemplate>
<div style="color: Red; font-weight: bold">
No data found.</div>
</NoRecordsTemplate>
<Columns>
 <telerik:GridNumericColumn DataField="ProductID" DataType="System.Int32" HeaderText="ProductID"
 SortExpression="ProductID" UniqueName="ProductID" ShowFilterIcon="false" AutoPostBackOnFilter="false"
CurrentFilterFunction="EqualTo" NumericType="Number" MaxLength="10" FilterControlWidth="60px"
HeaderStyle-Width="80px" ReadOnly="true" Groupable="false" AllowFiltering="true">
</telerik:GridNumericColumn>
<telerik:GridTemplateColumn DataField="ProductName" HeaderText="ProductName" AutoPostBackOnFilter="false"
FilterDelay="4000" ShowFilterIcon="false" SortExpression="ProductName" UniqueName="ProductName"
CurrentFilterFunction="Contains" ItemStyle-Wrap="false" FilterControlWidth="260px"
HeaderStyle-Width="280px" Groupable="false" AllowFiltering="true">
<ItemTemplate>
<asp:HyperLink ID="hlPName" runat="server" NavigateUrl='<%# Eval("CatalogPageLink")%>'
      Target="_blank" Text='<%# Eval("ProductName")%>' ToolTip="Get Catalog Details"></asp:HyperLink>
</ItemTemplate>
       </telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="EquipmentType" HeaderText="EquipmentType" SortExpression="EquipmentType"
UniqueName="EquipmentType" ShowFilterIcon="false" FilterControlWidth="140px"
HeaderStyle-Width="160px" ItemStyle-Wrap="false" AllowFiltering="true">
                      <FilterTemplate>
                         <telerik:RadComboBox ID="rcbEquip" runat="server" DataSourceID="dsGetEquipment"
AllowCustomText="true" DataTextField="EquipmentType" DataValueField="EquipmentTypeID"
Width="135px" AppendDataBoundItems="true" EmptyMessage="-- All Equipment --"
      HighlightTemplatedItems="true" AutoPostBack="true" TabIndex="1" Skin="Outlook"
OnClientDropDownOpening="OnClientDropDownOpening" OnClientDropDownClosing="OnClientDropDownClosing"
OnClientSelectedIndexChanging="OnClientSelectedIndexChanging" OnClientBlur="OnClientBlur"
OnClientDropDownClosed="onDropDownClosing">
<ItemTemplate>
<div onclick="stopPropagation(event);">
<asp:CheckBox runat="server" ID="cbEquipment" 
Text='<%# DataBinder.Eval(Container, "Text") %>' />
</div>
</ItemTemplate>
</telerik:RadComboBox>
<asp:SqlDataSource ID="dsEquipment" runat="server" ConnectionString="<%$ ConnectionStrings:connGait %>"
  SelectCommand="dbo.CTsp_PPT_GetEquipmentType" SelectCommandType="StoredProcedure" />
  </FilterTemplate>
</telerik:GridBoundColumn>
  </Columns>
</MasterTableView>
<ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True" ReorderColumnsOnClient="True"
EnableRowHoverStyle="true" EnablePostBackOnRowClick="false" AllowKeyboardNavigation="true"
ColumnsReorderMethod="Reorder">
<Resizing AllowColumnResize="True" EnableRealTimeResize="True" ResizeGridOnColumnResize="True" />
<Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true" FrozenColumnsCount="0">
</Scrolling>
<ClientMessages />
</ClientSettings>
<PagerStyle Mode="NextPrevNumericAndAdvanced" />
</telerik:RadGrid>


Server Side Code

protected void btnFilters_Click(object sender, EventArgs e)
   {
       GridFilteringItem item = rgPartnerPhone.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;
       //for ComboBox
       string strEquip = string.Empty;
       RadComboBox comborcbEquip = (RadComboBox)item.FindControl("rcbEquip");
       foreach (RadComboBoxItem ritem in comborcbEquip.Items)
       {
           CheckBox checkBox = (CheckBox)ritem.FindControl("cbEquipment");
           if (checkBox.Checked)
           {
               strEquip += ritem.Text + ",";
           }
       }
       if (!string.IsNullOrEmpty(strEquip))
           strEquip = strEquip.Remove(strEquip.Length - 1);
        
       string strProductID = (item["ProductID"].Controls[0] as RadNumericTextBox).Text;
       string strProductName = (item["ProductName"].Controls[0] as TextBox).Text;
       string strEquipType = strEquip;
       string expression = "";
     
       if (strProductID != "")
       {
           if (expression != "")
               expression += " AND ";
           expression += "([ProductID]  = \'" + strProductID + "\')";  
       }
       if (strProductName != "")
       {
           if (expression != "")
               expression += " AND ";
           expression += "([ProductName] LIKE \'%" + strProductName + "%\')";
       }
       if (strEquipType != "")
       {
           string[] words = strEquipType.Split(',');
           foreach (string citem in words)
           {
               if (expression != "")
                   expression += " AND ";
               expression += "([EquipmentType] LIKE \'%" + citem + "%\')";
           }
       }
       rgPartnerPhone.MasterTableView.GetColumnSafe("ProductID").CurrentFilterValue = strProductID;
       rgPartnerPhone.MasterTableView.GetColumnSafe("ProductName").CurrentFilterValue = strProductName;
      rgPartnerPhone.MasterTableView.GetColumnSafe("EquipmentType").CurrentFilterValue = strEquipType;
       rgPartnerPhone.MasterTableView.FilterExpression = expression;
       rgPartnerPhone.MasterTableView.Rebind();
   }

3 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 21 Apr 2011, 09:48 AM
Hello Jessy,

Please examine the Multi-Selection RadComboBox for filtering grid code library to see how the desired functionality can be implemented.

I hope it helps.

Greetings,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jessy Joseph
Top achievements
Rank 1
answered on 21 Apr 2011, 03:24 PM
Mira,

Thanks for the link, but can you help me how to achieve it when we click the "Search button" rather than autopost. Also in the link they have used a query but in my project I am using a stored procedure.

Thanks in advance,

Jessy
0
Mira
Telerik team
answered on 26 Apr 2011, 11:43 AM
Hello Jessy,

Thank you for the additional information

In order to implement the desired functionality, I recommend that you use the approach for fetching the data from the code library, but initiate the AJAX request when the Search button is clicked:
<FilterTemplate>
    <telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource1"
        DataValueField="EmployeeID" DataTextField="EmployeeID" EmptyMessage="All Types"
        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);
            }
            function removeLastComma(str) {
                return str.replace(/,$/, "");
            }
                             
        </script>
 
    </telerik:RadScriptBlock>
</FilterTemplate>
function searchButtonClick(sender, args) {
    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("EmployeeID," + text);   
}

Then, in the AjaxRequest event handler, you can set the filter expression of the grid manually as it is explained here.

I hope this helps.

Regards,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Jessy Joseph
Top achievements
Rank 1
Answers by
Mira
Telerik team
Jessy Joseph
Top achievements
Rank 1
Share this question
or