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

The total record is not correct while filtering record

2 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
john
Top achievements
Rank 1
john asked on 09 Oct 2012, 04:31 AM
I bound RadGrdid with objectdatasource control. While I filter the record, I found the total record is not correct. For example:
Before filter record, the total record is 32. After filter and bind grid again, the displayed total record is 10. In fact, the total record should be 17. I debug my code and found the GetTotalRecordCount also return 17 instead 10. The following is my code:

aspx:
<telerik:RadPageView ID="RadPageViewRule" runat="server">
                <div style="padding-left: 25px; padding-top: 30px">
                    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanelRule" runat="server" />
                    <telerik:RadGrid runat="server" ID="RadGridRule" AutoGenerateColumns="False" CellSpacing="0"
                        Width="850px" GridLines="None" DataSourceID="ObjectDataSourceRule" AllowPaging="true"
                        AllowFilteringByColumn="true" ShowStatusBar="false">
                        <ClientSettings EnableRowHoverStyle="true">
                            <Selecting AllowRowSelect="true" />
                        </ClientSettings>
                        <MasterTableView DataKeyNames="RuleId" CommandItemDisplay="Top">
                            <Columns>
                                <telerik:GridTemplateColumn ItemStyle-HorizontalAlign="Center" AllowFiltering="false"
                                    HeaderStyle-Width="20px" HeaderText="Action">
                                    <ItemTemplate>
                                        <asp:ImageButton runat="server" ImageUrl="~/Resource/Images/edit.png" ID="ImageButtonEdit" />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="S/N" HeaderStyle-Width="20px" AllowFiltering="false"
                                    ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <%# Container.DataSetIndex+1 %>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn HeaderText="PV Type" HeaderStyle-Width="100px" DataField="RuleType"
                                    UniqueName="RuleType">
                                    <FilterTemplate>
                                        <telerik:RadComboBox runat="server" Width="100px" ID="RadComboBoxRuleTypeFilter"
                                            OnClientSelectedIndexChanged="FieldRuleTypeIndexChanged">
                                        </telerik:RadComboBox>
                                        <telerik:RadScriptBlock ID="RadScriptBlockRuleType" runat="server">
                                            <script type="text/javascript">
                                                function FieldRuleTypeIndexChanged(sender, args) {
                                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                    tableView.filter("RuleType", args.get_item().get_value(), "EqualTo");
                                                }
                                            </script>
                                        </telerik:RadScriptBlock>
                                    </FilterTemplate>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn HeaderText="Function Name" DataField="FunctionId" UniqueName="FunctionId"
                                    HeaderStyle-Width="150px">
                                    <FilterTemplate>
                                        <telerik:RadComboBox runat="server" Width="150px" ID="RadComboBoxFunctionFilter"
                                            OnClientSelectedIndexChanged="FieldFunctionNameIndexChanged">
                                        </telerik:RadComboBox>
                                        <telerik:RadScriptBlock ID="RadScriptBlockFunctionName" runat="server">
                                            <script type="text/javascript">
                                                function FieldFunctionNameIndexChanged(sender, args) {
                                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                    tableView.filter("FunctionId", args.get_item().get_value(), "EqualTo");


                                                }
                                            </script>
                                        </telerik:RadScriptBlock>
                                    </FilterTemplate>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="RuleExpression" HeaderStyle-Width="370px" AllowFiltering="false"
                                    HeaderText="Rule Expression" HtmlEncode="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridButtonColumn ConfirmText="Do you confirm to delete the record?" ConfirmDialogType="RadWindow"
                                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" ConfirmDialogHeight="150px"
                                    HeaderText="Delete" ConfirmDialogWidth="320px" ItemStyle-Width="30px">
                                    <ItemStyle HorizontalAlign="Center" />
                                </telerik:GridButtonColumn>
                            </Columns>
                        </MasterTableView>
                        <ClientSettings>
                            <Selecting AllowRowSelect="true" />
                        </ClientSettings>
                        <PagerStyle AlwaysVisible="true" />
                    </telerik:RadGrid>
                    </telerik:RadAjaxLoadingPanel>
                    <asp:ObjectDataSource ID="ObjectDataSourceRule" runat="server" EnablePaging="true"
                        OnSelecting="ObjectDataSourceRule_Selecting" SelectCountMethod="GetTotalRecord"
                        SelectMethod="GetRuleData" TypeName="BTSIS.Business.MaintainRuleBC">
                        <SelectParameters>
                            <asp:Parameter Name="filterExpressions" Type="String" ConvertEmptyStringToNull="true" />
                        </SelectParameters>
                    </asp:ObjectDataSource>


CS code:
   protected void ObjectDataSourceRule_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            if (e.ExecutingSelectCount) return;
            
            string expression = RadGridRule.MasterTableView.FilterExpression;


            if (!expression.Contains("RuleType") && expression.Contains("FunctionId"))
            {
                expression = string.Empty;
            }


            RadGridRule.MasterTableView.FilterExpression = expression;
            e.InputParameters["filterExpressions"] = expression;


            if (e.Arguments.MaximumRows == int.MaxValue) e.Arguments.MaximumRows = this.RadGridRule.MasterTableView.PageSize;            
        }

2 Answers, 1 is accepted

Sort by
0
john
Top achievements
Rank 1
answered on 10 Oct 2012, 04:02 AM
Any solution?
0
Angel Petrov
Telerik team
answered on 11 Oct 2012, 04:57 PM
Hello John,

Based on the provided code I can not tell for sure what is the origin of the problem. Could you please define what is your data and what are the expected result? If you could send runnable project we would be able to find why this issue occurs.

Greetings,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
john
Top achievements
Rank 1
Answers by
john
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or