Trouble Populating ListView with Search Results

2 posts, 0 answers
  1. Jim
    Jim avatar
    8 posts
    Member since:
    Sep 2010

    Posted 28 Jul 2011 Link to this post


    I am hoping someone can help me with this issue.

    I have a RadTextbox (search box), a RadButton (search button), and a RadListView.  I am using the NeedDataSource event to populate my list view with data.  On page load, the list view loads up with data as expected.  The problem comes in when I use the search box and button to refine my data.

    When I click the search button to initiate the search, the NeedDataSource event fires before the RadButton Click event.  Therefore, I have to click the search button twice to get my expected results.  The search text is captured in the code behind on the first click event, but then doesn't apply it until the second time around.  I think this is the normal behavior according to Telerik's documentation (Other Postback events occur after the NeedDataSource event in the page lifecycle - see this link)

    Can someone please help?  This is a very basic need, but I am really struggling with it.

    Thank you, Jim

    Here is a snippet of the code that I am using.

    <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <telerik:AjaxSetting AjaxControlID="SearchButton">
                    <telerik:AjaxUpdatedControl ControlID="ProductsView" />
            <telerik:AjaxSetting AjaxControlID="ProductView">
                    <telerik:AjaxUpdatedControl ControlID="ProductView" />
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <telerik:AjaxUpdatedControl ControlID="CartPanel" LoadingPanelID="RadAjaxLoadingPanel1" />
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Black" />
        <div class="searchContainer">
            <div style="float: left; color: #99CA3B; margin-right: 15px; font-size: 16px; font-weight: bold;">Search Hort Couture™ Products</div>
            <div class="searchBox">
                <telerik:RadTextBox ID="SearchBox" BackColor="#191919" ForeColor="#99CA3B" BorderColor="#C9C9C9" BorderWidth="1" Font-Size="14px" Width="380" runat="server"></telerik:RadTextBox>
            <div class="searchButton">
                <telerik:RadButton ID="SearchButton" Text="Search" runat="server"></telerik:RadButton>
        <div class="productContainer">
            <asp:Panel ID="ProductPanel" runat="server">
                <telerik:RadListView ID="ProductView" runat="server" Height="400"
                    ItemPlaceholderID="ItemContainer" Skin="Black" DataKeyNames="culturalInfoId,longName,seriesDesc,cultivarDesc" AllowPaging="true" PageSize="12">
                        <div class="RadListView RadListView_<%# Container.Skin %>">
                            <asp:PlaceHolder ID="ItemContainer" runat="server"></asp:PlaceHolder>
                        <div style="clear: both"></div>
                        <div style="padding: 5px;">
                            <div style="float: left; margin-left: 30%;">
                                <asp:Button runat="server" ID="btnFirst" CommandName="Page" CommandArgument="First"
                                    Text="First" Enabled="<%#Container.CurrentPageIndex > 0 %>" />
                                <asp:Button runat="server" ID="btnPrev" CommandName="Page" CommandArgument="Prev"
                                    Text="Prev" Enabled="<%#Container.CurrentPageIndex > 0 %>" />
                                <span style="vertical-align: middle;">
                                    Page <strong><%#Container.CurrentPageIndex + 1 %></strong> of <strong><%#Container.PageCount %></strong>
                                <asp:Button runat="server" ID="btnNext" CommandName="Page" CommandArgument="Next"
                                    Text="Next" Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>" />
                                <asp:Button runat="server" ID="btnLast" CommandName="Page" CommandArgument="Last"
                                    Text="Last" Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>" />
                        <div class="item">
                            <img class="itemImage" src="<%# Eval("standardFileName") %>" />
                            <div class="itemDesc">
                                <%# Eval("seriesDesc")%> <%# Eval("cultivarDesc")%></div>
                            <div class="itemActions">
                                <a onclick="ShowDetail('<%# Eval("culturalInfoId") %>');" href="javascript:void(0);">PRODUCT DETAIL</a>
                            No Item.

    Private Sub ProductView_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewNeedDataSourceEventArgs) Handles ProductView.NeedDataSource
        Dim sql As New sqlProcedures()
        Dim products As New DataSet()
        Dim contains As String = Session("SearchText")
        If (contains Is Nothing) Then
            products = sql.spSelectItemsBySmartSearch("%")
            products = sql.spSelectItemsBySmartSearch(contains)
        End If
        ProductView.DataSource = products
    End Sub
    Private Sub SearchButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchButton.Click
        Session("SearchText") = SearchBox.Text
    End Sub
  2. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 02 Aug 2011 Link to this post

    Hi Jim,

    Assuming it is enabled, ViewState will take care of what you are trying to do without you needing to store the search criteria in Session.

    In your NeedDataSource method you should be able to do this instead of using Session -- which will get you around the page lifecycle issue.

    Private Sub ProductView_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewNeedDataSourceEventArgs) Handles ProductView.NeedDataSource
        Dim contains As String = SearchBox.Text
    End Sub

    If you still need to store the text in session you can do it either here or in the SearchButton_Click event like you currently are doing.

    Hope that helps!
Back to Top