Search records in RadListView

2 posts, 0 answers
  1. Rasha
    Rasha avatar
    4 posts
    Member since:
    Apr 2013

    Posted 08 May 2013 Link to this post

    Hi, 
    Im using Rad ListView in my application and everything was going great until I decided to add search functionality, the search was a success and it displays the records founded the problem is if the found records were in different pages see what happens once I go to another page is that it cancels the search somehow and it reloads all the original records
     this is my ListView
    <telerik:RadListView ID="packageListView" runat="server"
                   DataKeyNames="PackageID"
                   ItemPlaceholderID="PackageContainer" AllowPaging="True"
                   OnItemCommand="packageListView_ItemCommand"  OnNeedDataSource="packageListView_NeedDataSource">
                   <LayoutTemplate>
                       <fieldset style="max-width: 946px;">
                           <legend>Package</legend>
                           <table cellpadding="0" cellspacing="0" width="100%">
                               <tr>
                                   <td>
                                       <telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="packageListView" PageSize="1" CssClass="pagerStyle">
                                           <Fields>
                                               <telerik:RadDataPagerButtonField FieldType="First"/>
                                               <telerik:RadDataPagerButtonField FieldType="Numeric"/>
                                               <telerik:RadDataPagerButtonField FieldType="NextLast" />
                                               <telerik:RadDataPagerPageSizeField PageSizeComboWidth="60" PageSizeText="Page Size: "/>
                                               <telerik:RadDataPagerGoToPageField CurrentPageText="Page: " TotalPageText="of" SubmitButtonText="Go" TextBoxWidth="25" />
                                               <telerik:RadDataPagerTemplatePageField>
                                                   <PagerTemplate>
                                                       <div style="float: right; padding-left: 50px;">
                                                           <b>Items
                                                              <asp:Label runat="server" ID="CurrentPageLabel" Text="<%# (Container.Owner.TotalRowCount > 0)? Container.Owner.StartRowIndex + 1  : 0%>"></asp:Label>
                                                                           to
                                                                           <asp:Label runat="server" ID="TotalPagesLabel" Text="<%# (Container.Owner.TotalRowCount > 0)? Container.Owner.StartRowIndex + Container.Owner.PageSize : 0 %>"></asp:Label>
                                                                           of
                                                                           <asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.Owner.TotalRowCount%>"></asp:Label>
                                                               <br />
                                                           </b>
                                                       </div>
                                                         
                                                   </PagerTemplate>
                                               </telerik:RadDataPagerTemplatePageField>
                                           </Fields>
                                       </telerik:RadDataPager>
                                       
                                   </td>
                               </tr>
                           </table>
                           <asp:PlaceHolder runat="server" ID="PackageContainer"></asp:PlaceHolder>
                           <div style="clear: both"></div>
                           <table style="width: 100%; margin-top: 5px;">
                               <tr>
                                   <td style="width: 25%;">
                                       <asp:Button ID="btnInitInsert" runat="server" Text="Insert Package" OnClick="btnInitInsert_Click"/>   
                                   </td>
                                   <td style="text-align: right; width: 75%;">
                                       <asp:Label ID="lblSort1" runat="server" Text="Sort by:" AssociatedControlID="ddListSort" Style="padding-right: 5px;"></asp:Label>
                                       <telerik:RadComboBox ID="ddListSort" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddListSort_SelectedIndexChanged">
                                           <Items>
                                               <telerik:RadComboBoxItem Text="-Select Field to Sort" Value=""/>
                                               <telerik:RadComboBoxItem Text="Package Name" Value="CompanyName" />
                                               <telerik:RadComboBoxItem  Text="Price" Value="PricePerMonth"/>
                                               <telerik:RadComboBoxItem Text="Clear Sort" Value="ClearSort"/>
                                           </Items>
                                       </telerik:RadComboBox
                                       <asp:RadioButtonList runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal" ID="rblSort" AutoPostBack="true" OnSelectedIndexChanged="rblSort_SelectedIndexChanged">
                                           <asp:ListItem Text="Ascending" Value="ASC" Selected="True"></asp:ListItem>
                                           <asp:ListItem Text="Descending" Value="DESC"></asp:ListItem>
                                       </asp:RadioButtonList>
                                   </td>
                               </tr>
                           </table>
                       </fieldset>
                   </LayoutTemplate>
                   <ItemTemplate>
                       <!--The widths/heights of the fieldset/outer tables in the item/edit/insert templates should match to avoid wrapping or visual discrepancies
                                        in the tiles layout-->
                       <fieldset class="fieldset">
                           <legend>Package Name:
                              <%# Eval("PackageName") %> </legend>
                           <table cellpadding="0" cellspacing="0" style="height: 100%; width:100%;">
                               <tr>
                                   <td>
                                      <table cellpadding="0" cellspacing="0" style="width: 95%">
                                       <tr>
                                           <td>
                                               <table cellpadding="0" cellspacing="0">
                                                   <tr>
                                                       <td style="width:25%">
                                                         Description:
                                                       </td>
                                                       <td style="width: 50%">
                                                           <%# Eval("PackageDesc") %>
                                                       </td>
                                                   </tr>
                                                   <tr>
                                                       <td>
                                                           Price(per Month):
                                                       </td>
                                                       <td>
                                                           <%# Eval("PricePerMonth") %>
                                                       </td>
                                                   </tr>
                                                   <tr>
                                                       <td>
                                                           Discount:
                                                       </td>
                                                       <td>
                                                           <%# Eval("discountPercent") %>
                                                       </td>
                                                   </tr>
                                                   <tr>
                                                       <td>
                                                           Number of Images:
                                                       </td>
                                                       <td>
                                                           <%# Eval("NumOfImg") %>
                                                       </td>
                                                   </tr>
                                                   <tr>
                                                       <td>
                                                          Numbrt of GIF:
                                                       </td>
                                                       <td>
                                                           <%# Eval("NumOfGIF") %>
                                                       </td>
                                                   </tr>
                                                   <tr>
                                                       <td>
                                                           Number Of Flash:
                                                       </td>
                                                       <td>
                                                           <%# Eval("NumOfFlash") %>
                                                       </td>
                                                   </tr>
                                                   <tr>
                                                       <td>
                                                           Home Page Included(Yes/No)
                                                       </td>
                                                       <td>
                                                           <%# Eval("isHomePageIncluded") %>
                                                       </td>
                                                   </tr>
                                               </table>
                                           </td>
                                       </tr>
                                      </table>
                                   </td>
                               </tr>
                               <tr>
                                   <td>
                                       <table style="width: 95%; margin-top: 30px">
                                           <tr>
                                               <td>
                                                   <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" Width="70px"/>
                                               </td>
                                               <td style="text-align: right">
                                                   <asp:Button ID="btnDelete" runat="server" Text="Delete" CommandName="Delete" Width="70px" OnClientClick="return confirm('Are you certain you want to delete?');"/>
                                               </td>
                                           </tr>
                                       </table>
                                   </td>
                               </tr>
                           </table>
                       </fieldset>
                   </ItemTemplate>
     
                   <EditItemTemplate>
                       <!--The widths/heights of the fieldset/outer tables in the item/edit/insert templates should match to avoid wrapping or visual discrepancies
                       in the tiles layout-->
                       <fieldset class="fieldset">
                           <legend>
                               Package Name:
                               <asp:TextBox ID="txtPackageName" runat="server" Text='<%# Bind("PackageName") %>'></asp:TextBox>
                               <asp:RequiredFieldValidator ID="rvPackageName" runat="server" ControlToValidate="txtPackageName" ErrorMessage="Please Enter Package Name" Display="Dynamic"></asp:RequiredFieldValidator>
                           </legend>
                           <table cellpadding="0" cellspacing="0" style="height: 80%;" width="100%">
                               <tr>
                                   <td>
                                       <table cellpadding="0" cellspacing="0" style="width: 95%; margin-bottom: 5px">
                                           <tr>
                                               <td>
                                                   <table cellpadding="0" cellspacing="2">
                                                       <tr>
                                                           <td style="width: 25%">
                                                              Description:
                                                           </td>
                                                           <td>
                                                               <asp:TextBox ID="txtPackageDesc" runat="server" Text='<%# Bind("PackageDesc") %>' TextMode="MultiLine"></asp:TextBox>
                                                           </td>
                                                       </tr>
                                                       <tr>
                                                           <td>
                                                               Price(per Month):
                                                           </td>
                                                           <td>
                                                               <asp:TextBox ID="txtPricePerMonth" runat="server" Text='<%# Bind("PricePerMonth") %>'></asp:TextBox>
                                                               <asp:RequiredFieldValidator ID="rvPricePerMonth" runat="server" ControlToValidate="txtPricePerMonth" ErrorMessage="Please Enter the Package Price" Display="Dynamic"></asp:RequiredFieldValidator>
                                                           </td>
                                                       </tr>
                                                       <tr>
                                                           <td>
                                                               Discount:
                                                           </td>
                                                           <td>
                                                               <asp:TextBox ID="txtDiscountPercent" runat="server" Text='<%# Bind("DiscountPercent") %>'></asp:TextBox>
                                                               <asp:RequiredFieldValidator ID="rvDiscountPercent" runat="server" ControlToValidate="txtDiscountPercent" ErrorMessage="Please Enter Discount Value (min:0)" Display="Dynamic"></asp:RequiredFieldValidator>
                                                           </td>
                                                       </tr>
                                                        <tr>
                                                           <td>
                                                               Number of Images:
                                                           </td>
                                                           <td>
                                                               <asp:TextBox ID="txtNumOfImg" runat="server" Text='<%# Bind("NumOfImg") %>'></asp:TextBox>
                                                               <asp:RequiredFieldValidator ID="rvNumOfImg" runat="server" ControlToValidate="txtNumOfImg" ErrorMessage="Please Enter The Number of Images" Display="Dynamic"></asp:RequiredFieldValidator>
                                                           </td>
                                                       </tr>
                                                        <tr>
                                                           <td>
                                                               Number of GIF:
                                                           </td>
                                                           <td>
                                                               <asp:TextBox ID="txtNumOfGIF" runat="server" Text='<%# Bind("NumOfGIF") %>' TextMode="MultiLine"></asp:TextBox>
                                                               <asp:RequiredFieldValidator ID="rvNumOfGIF" runat="server" ControlToValidate="txtNumOfGIF" ErrorMessage="Please Enter The Nuber of GIF(s)" Display="Dynamic"></asp:RequiredFieldValidator>
                                                           </td>
                                                       </tr>
                                                       <tr>
                                                           <td>
                                                               Number of Flash:
                                                           </td>
                                                           <td>
                                                               <asp:TextBox ID="txtNumOfFlash" runat="server" Text='<%# Bind("NumOfFlash") %>'></asp:TextBox>
                                                               <asp:RequiredFieldValidator ID="rvNumOfFlash" runat="server" ControlToValidate="txtNumOfFlash" ErrorMessage="Please Enter The Number of Flash File(s)" Display="Dynamic"></asp:RequiredFieldValidator>
                                                           </td>
                                                       </tr>
                                                        <tr>
                                                           <td>
                                                               Home page Included(Yes/No):
                                                           </td>
                                                           <td>
                                                               <asp:CheckBox runat="server" ID="cbIsHomePageIncliuded" Checked='<%# Bind("isHomePageIncluded")%>' />
                                                           </td>
                                                       </tr>
                                                   </table>
                                               </td>
                                              
                                           </tr>
                                           <tr>
                                               <td colspan="2">
                                               <div style="clear: both">
                                               </div>
                                               <div style="float: left; padding-left: 30%;">
                                                   <asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" /> 
                                                   <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false"/>
                                               </div>
                                           </td>
                                        </tr>
                                       </table>
                                   </td>
                               </tr>
                           </table>
                       </fieldset>
                   </EditItemTemplate>
                   <InsertItemTemplate>
                   <!--The widths/heights of the fieldset/outer tables in the item/edit/insert templates should match to avoid wrapping or visual discrepancies
                   in the tiles layout-->
                   <fieldset class="fieldset" style="clear: left; width: 540px">
                       <legend>Package Name:
                           <asp:TextBox ID="txtPackageName" runat="server" Text='<%# Bind("PackageName") %>'></asp:TextBox>
                           <asp:RequiredFieldValidator ID="rvPackageNamee" runat="server" ControlToValidate="txtPackageName"
                               ErrorMessage="Please enter Package Name" Display="Dynamic"></asp:RequiredFieldValidator>
                        </legend>
                   <table cellpadding="0" cellspacing="0" style="height: 80%;" width="100%">
                       <tr>
                           <td>
                               <table cellpadding="0" cellspacing="5" style="width: 95%; margin-bottom: 5px">
                                   <tr>
                                       <td style="width: 25%">
                                           Description:
                                       </td>
                                       <td style="width: 75%">
                                           <asp:TextBox ID="txtPackageDesc" runat="server" Text='<%# Bind("PackageDesc") %>'></asp:TextBox>
                                           <asp:RequiredFieldValidator ID="rvPackageDesc" runat="server" ControlToValidate="txtPackageDesc" ErrorMessage="Please Enter Package Description" Display="Dynamic"></asp:RequiredFieldValidator>
                                       </td>
                                   </tr>
                                   <tr>
                                       <td>
                                           Price(per Month):
                                       </td>
                                       <td>
                                           <asp:TextBox ID="txtPricePerMonth" runat="server" Text='<%# Bind("PricePerMonth") %>'></asp:TextBox>
                                           <asp:RequiredFieldValidator ID="rvPricePerMonth" runat="server" ControlToValidate="txtPricePerMonth" ErrorMessage="Please Enter Package Price" Display="Dynamic"></asp:RequiredFieldValidator>
                                       </td>
                                   </tr>
                                   <tr>
                                       <td>
                                           Discount:
                                       </td>
                                       <td>
                                           <asp:TextBox ID="txtDiscountPercent" runat="server" Text='<%# Bind("DiscountPercent") %>'></asp:TextBox
                                           <asp:RequiredFieldValidator ID="rvDiscountPercent" runat="server" ControlToValidate="txtDiscountPercent" ErrorMessage="Please Enter Discount Value (min:0)" Display="Dynamic"></asp:RequiredFieldValidator>
                                       </td>
                                   </tr>
                                   <tr>
                                       <td>
                                         Number of Images:
                                       </td>
                                       <td>
                                           <asp:TextBox ID="txtNumOfImg" runat="server" Text='<%# Bind("NumOfImg") %>'></asp:TextBox
                                           <asp:RequiredFieldValidator ID="rvNumOfImg" runat="server" ControlToValidate="txtNumOfImg" ErrorMessage="Please Enter Number of Image(s)" Display="Dynamic"></asp:RequiredFieldValidator>
                                       </td>
                                   </tr>
                                   <tr>
                                        <td>
                                           Number of GIF:
                                       </td>
                                       <td>
                                           <asp:TextBox ID="txtNumOfGIF" runat="server" Text='<%# Bind("NumOfGIF") %>'></asp:TextBox
                                           <asp:RequiredFieldValidator ID="rvNumOfGIF" runat="server" ControlToValidate="txtNumOfGIF" ErrorMessage="Please Enter Number of GIF(s)" Display="Dynamic"></asp:RequiredFieldValidator>
                                       </td>
                                   </tr>
     
                                   <tr>
                                       <td>
                                           Number of Flash:
                                       </td>
                                       <td>
                                           <asp:TextBox ID="txtNumOfFlash" runat="server" Text='<%# Bind("NumOfFlash") %>'></asp:TextBox
                                           <asp:RequiredFieldValidator ID="rvNumOfFlash" runat="server" ControlToValidate="txtNumOfFlash" ErrorMessage="Please Enter Number of Flash File(s)" Display="Dynamic"></asp:RequiredFieldValidator>
                                       </td>
                                   </tr>
                                   <tr>
                                        <td>
                                          Home Page Included(Yes/No):
                                       </td>
                                       <td>
                                            <asp:CheckBox runat="server" ID="cbIsHomePageIncliuded" Checked='<%# Bind("isHomePageIncluded")%>' />
                                       </td>
                                   </tr>        
                               </table>
                           </td>
                       </tr>
                        <tr>
                           <td colspan="2">
                               <div style="clear: both">
                               </div>
                               <div style="float: left; padding-left: 40%;">
                                    <asp:Button ID="btnPerformInsert" runat="server" Text="Insert" CommandName="PerformInsert"></asp:Button>
                                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false"> </asp:Button>
                               </div>
                           </td>
                       </tr>
                   </table>
                   </fieldset>
                   </InsertItemTemplate>
                   <EmptyDataTemplate>
                       <fieldset style="width: 800px">
                       <legend>Packages</legend>No records for Packages available.
                       </fieldset>
                   </EmptyDataTemplate>
               </telerik:RadListView>
    and here is the code of my search Button click event handler 
    public void btn_Search_Click(object sendr, EventArgs e)
          {
              packageDBDataContext db = new packageDBDataContext();
              var query = from contact in db.Packages
                          where contact.PackageName.Contains(txtSearch.Text.Trim())
              select contact;
              packageListView.DataSource = query;
              packageListView.DataBind();
              
     
          }
    Help please it is quite an annoying problem
    Thanks in advance 
    PS. : Sorry if the code seems a bit long :) it is just basic, only a lot of templates 
  2. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 13 May 2013 Link to this post

    Hi Rasha,

    Please note that using DataBind() is not recommended. Performing complex listview operations such as Inserting, Deleting, Updating, Paging, Sorting, Filtering require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions: Declarative DataSource or Advanced Data Binding:
    http://www.telerik.com/help/aspnet-ajax/listview-simple-vs-advanced-binding.html

    Additionally, you can check out the following examples for implementing the requested approach:
    http://demos.telerik.com/aspnet-ajax/listview/examples/filtering/defaultcs.aspx
    http://demos.telerik.com/aspnet-ajax/listview/examples/filteringwithradfilter/defaultcs.aspx

    Hope this helps.

    Regards,
    Eyup
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top