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

Combo box loosing values after postback.

1 Answer 467 Views
ComboBox
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:
ASPX Code

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title></title>
</head>
<body>

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

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

 
    <p>
        &nbsp;</p>
  
 
    <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">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>

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

<EditFormSettings>
<EditColumn UniqueName="EditCommandColumn1"></EditColumn>
</EditFormSettings>
</MasterTableView>
        <GroupingSettings CaseSensitive="False" />
    </telerik:RadGrid>
  
 
    <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>
  
  </form>
  
    </body>
</html>


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
0
Kalina
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,
Kalina
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.
Tags
ComboBox
Asked by
Kevin Kess
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Share this question
or