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

Checked RadComboBox loosing checked state on postback

4 Answers 186 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 19 May 2014, 08:45 PM
I have a Radcombobox defined as...

<telerik:RadComboBox ID="RadComboBrandCodes2" runat="server" CheckBoxes="true" ViewStateMode="Enabled" EnableViewState="true"
DataSourceID="sdsBrandCodes" DataTextField="Description" DataValueField = "Description"
Height="150px"></telerik:RadComboBox>

this combo is inside a filter template in a radgrid. When a Ajax postback happens, the items in the combo box loose their checked status. If I make a copy of the exact same markup and put it outside the grid but still within the div that gets updated via the ajax call, the checked status is maintained through the postback.

How can I get the checked state to be the same after the postback as it was before for the combo box in the filter template?

Thx,
Jeff

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 May 2014, 05:01 AM
Hi Daniel,

Please have a look into the sample code snippet which works fine at my end. Please provide your full code if it doesn't help.

ASPX:
<telerik:RadButton ID="RadButton1" runat="server" Text="PostBack">
</telerik:RadButton>
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AllowFilteringByColumn="true">
    <MasterTableView>
        <Columns>
            <telerik:GridTemplateColumn>
                <FilterTemplate>
                    <telerik:RadComboBox ID="RadComboBox1" CheckBoxes="true" runat="server" DataSourceID="SqlDataSource1" DataTextField="CustomerID" DataValueField="OrderID">
                    </telerik:RadComboBox>
                </FilterTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Thanks,
Shinu.
0
Daniel
Top achievements
Rank 1
answered on 20 May 2014, 02:57 PM
This appears to be happening because of a rebind call on the grid in the code behine when the 'Apply filter' button is pressed. It's a filter template and because I am using custom paging, I have to use code behind to get the values that were checked and modify the DB query to filter out data that does not apply based on the items checked. I could not find a way to fire an ajax postback without adding a button to the filter template to 'apply' the filter although I did see some examples that used JavaScript to fire the ajax callback. I believe that the java script did not work because the page uses a RadAjaxManagerProxy instead of a RadAjaxManager.

If i could get a good and COMPELTE example of how to use a Checked RadComboBox as a column filter, it would help quite a bit.

If you still need the code, I would prefer to open a ticket as there is a lot of code. probably too much to paste in the forum.

Thanks,


0
Daniel
Top achievements
Rank 1
answered on 20 May 2014, 03:03 PM
Here is the definition of the column in question.

<telerik:GridBoundColumn UniqueName="BrandCode" HeaderText="Brand Code" DataField="BrandCode" DataType="System.String" AllowFiltering="true">
    <FilterTemplate>
        <telerik:RadComboBox ID="RadComboBrandCodes" runat="server" CheckBoxes="true"
            DataSourceID="sdsBrandCodes" DataTextField="Description" DataValueField = "Description" 
            Height="150px">
        </telerik:RadComboBox>
        <telerik:RadButton ID="RBBrandCodesOk" runat="server" Width="20px" ToolTip="Apply Filter" OnClick="RBBrandCodesOk_Click" >
            <Icon PrimaryIconCssClass="rbOk" PrimaryIconLeft="5" PrimaryIconTop="5"></Icon>
        </telerik:RadButton>
        <telerik:RadButton ID="RBBrandCodesClear" runat="server" Width="20px" ToolTip="Clear Filter"
            OnClientClicking="RBBrandCodesClear_OnClientClicking"
            OnClick="RBBrandCodesClear_Click">
            <Icon PrimaryIconCssClass="rbCancel" PrimaryIconLeft="5" PrimaryIconTop="5"></Icon>
        </telerik:RadButton>
        <telerik:RadScriptBlock ID="RadComboBrandCodesScriptBlock" runat="server">
            <script type="text/javascript">
                function RCBBrandCodes_OnClientSelectedIndexChanged(sender, args) {
                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                    tableView.filter("BrandCode", args.get_item().get_value(), "EqualTo");
                }
                function RBBrandCodesClear_OnClientClicking(sender, args) {
                    var combo = $find('<%# ((GridItem)Container).FindControl("RadComboBrandCodes").ClientID %>');
                    for (var i = 0; i < combo.get_items().get_count() ; i++) {
                        combo.get_items().getItem(i).set_checked(false);
                    }
                }
            </script>
        </telerik:RadScriptBlock>
    </FilterTemplate>
</telerik:GridBoundColumn>
0
Nencho
Telerik team
answered on 22 May 2014, 02:36 PM
Hello Daniel,

The experienced issue is indeed caused by the rebind of the RadGrid, which pushes the radComboBox  to rebind. I would suggest you to handle the ItemCommand event and store in a hidden field the currently checked items. Then at the ItemDataBound event of the grid, you could access the hiddenField, and use the stored values to manually check the Items of the RadComboBox.

I have prepared a sample project for you, demonstrating the implementation of the above suggestion.

Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ComboBox
Asked by
Daniel
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Daniel
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or