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

Combo box loosing values after postback.

1 Answer 416 Views
This is a migrated thread and some comments may be shown as answers.
Kevin Kess
Top achievements
Rank 1
Kevin Kess asked on 13 Apr 2010, 02:33 PM
I am using the combobox as a filter in a grid. I wanted to use the combobox in a column to filter out values. It works great in the code the first time. But I was noticing on every postback when I select a filter value, it would again keep making retreivals to the DB to fill the combo box with values again and again. So I figured that I would check the postback condition, and just not bind in that case thinking, the combox box would still have values in it from the original call and since the EnableViewState flag is true. But the values don't stay on postback. How can I fix this:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LaunchPage.aspx.cs" Inherits="SearchDesk.LaunchPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head id="Head1" runat="server">

   banner : User ID :
    <asp:Label ID="lblUserID" runat="server"  Text=""></asp:Label>

    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"
        AllowSorting="True" AutoGenerateColumns="False" GridLines="None"
        onneeddatasource="RadGrid1_NeedDataSource" onsortcommand="RadGrid1_SortCommand"
        onupdatecommand="RadGrid1_UpdateCommand" Width="585px">
<HeaderContextMenu EnableAutoScroll="True"></HeaderContextMenu>

<MasterTableView DataKeyNames="SearchID">
<HeaderStyle Width="20px"></HeaderStyle>

<HeaderStyle Width="20px"></HeaderStyle>
        Currently no open searches.....
        <telerik:GridBoundColumn DataField="SearchName" HeaderText="Search Name"
            SortExpression="SearchName" UniqueName="SearchName">
        <telerik:GridTemplateColumn DataField="StatusName" HeaderText="Search Status"
            SortExpression="StatusName" UniqueName="StatusName">
                <asp:Label ID="StatusNameLabel" runat="server" Text='<%# Eval("StatusName") %>'></asp:Label>
                <telerik:RadComboBox ID="cboFilterStatus" Runat="server"
                    ondatabinding="cboFilterStatus_DataBinding" DataTextField="SearchStatusName"
        DataValueField="SearchStatusName" AutoPostBack="True"
                    ondatabound="cboFilterStatus_DataBound" EnableAutomaticLoadOnDemand="True">
        <telerik:GridBoundColumn DataField="DateOpened" HeaderText="Date Opened"
            SortExpression="DateOpened" UniqueName="column1">
        <telerik:GridBoundColumn DataField="Age" HeaderText="Age" SortExpression="Age"

<EditColumn UniqueName="EditCommandColumn1"></EditColumn>
        <GroupingSettings CaseSensitive="False" />
    <asp:LinkButton ID="linkNew"  runat="server">Create New Search</asp:LinkButton><br />
    <asp:LinkButton ID="linkAdmin1" PostBackUrl="Utils/ChangeUser.aspx" runat="server">Change User</asp:LinkButton>
    <br />
    <asp:LinkButton ID="linkAdmin2" runat="server">Admin 2</asp:LinkButton>

c# code behind:
protected void cboFilterStatus_DataBinding(object sender, EventArgs e)
      if (!Page.IsPostBack){
        ((RadComboBox) sender).DataSource =
          Searches.GetListOfSearchStatus().Select(s => new{s.SearchStatusID, s.SearchStatusName});

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 16 Apr 2010, 12:28 PM
Hi Kevin Kess,

At first let me explain to you how Load-On-Demand feature works. On the initial page load the RadComboBox is empty - there are no items in the dropdown. When the user types in the input area or clicks on the drop-down toggle image - Load-On-Demand fires and populates the dropdown with data. The Automatic Load-On-Demand works in the same way but the implementation there is codeless and much easier. Additionally the RadComboBox items collection in this case is not persisted between page postbacks.

As I understand from your code you are trying to filter a RadGrid with a RadComboBox nested within the FilterTemplate of the grid.  You use Automatic Load-On-Demand, at the same time the AutoPostBack property of the control is set to true. I suppose you are trying to obtain the selected text or value of the RadComboBox in order to filter the grid.

I recommend you use a better approach. You can achieve filtering the RadGrid with RadComboBox very easy by following this online example.

Please note that filtering there is implemented client-side (take a look at the “Country” RadComboBox).

Best wishes,
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Asked by
Kevin Kess
Top achievements
Rank 1
Answers by
Telerik team
Share this question