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

Trouble Populating ListView with Search Results

1 Answer 69 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 2
Jim asked on 28 Jul 2011, 03:15 PM
Hello,

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">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="SearchButton">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="ProductsView" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="ProductView">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="ProductView" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="CartPanel" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
 
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Black" />
 
<div>
    <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>
        <div class="searchButton">
            <telerik:RadButton ID="SearchButton" Text="Search" runat="server"></telerik:RadButton>
        </div>
    </div>
 
    <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">
                <LayoutTemplate>
                    <div class="RadListView RadListView_<%# Container.Skin %>">
                        <asp:PlaceHolder ID="ItemContainer" runat="server"></asp:PlaceHolder>
                    </div>
                    <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>
                            </span>
                            <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>
                    </div>
                </LayoutTemplate>
                <ItemTemplate>
                    <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>
                        </div>
                    </div>
                </ItemTemplate>
                <EmptyItemTemplate>
                    <div>
                        No Item.
                    </div>
                </EmptyItemTemplate>
            </telerik:RadListView>
        </asp:Panel>
    </div>
</div>


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("%")
    Else
        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

1 Answer, 1 is accepted

Sort by
0
Thad
Top achievements
Rank 2
answered on 03 Aug 2011, 12:40 AM
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!
Thad
Tags
ListView
Asked by
Jim
Top achievements
Rank 2
Answers by
Thad
Top achievements
Rank 2
Share this question
or