Radgrid Telerik上的默认过滤器错误,列号

时间:2014-10-27 10:02:16

标签: c# filter telerik tooltip radgrid

我有一个Radgrid页面。一切正常,直到我实现自定义过滤器并设置默认过滤器取决于会话。我在列标题上做了一个工具提示,允许用户为过滤器radgrid选择一个项目。

enter image description here

所有列都运行良好,除了" TotalAmount"柱。当我点击工具提示上的项目时没有任何反应。

enter image description here

当用户点击工具提示上的项目(Radgrid_PreRender)时,代码设置默认过滤器:

 if (!IsPostBack)
        {
            if (Session["FilterParams"] != null)
            {
                ParamsForGrid prForGrid = new ParamsForGrid();
                Filters filter = new Filters();
                filter = prForGrid.GetFilter();
                rgOrders.MasterTableView.FilterExpression = "([" + filter.columnName + "] LIKE \'%" + filter.searchStrings + "%\') ";
                GridColumn column = rgOrders.MasterTableView.GetColumnSafe(filter.columnName);
                column.CurrentFilterFunction = GridKnownFunction.Contains;
                column.CurrentFilterValue = filter.searchStrings;
                rgOrders.MasterTableView.Rebind();
            }

        }

如何修复它。我使用telerik控制版本2012.3.1016.35

更新:在我点击工具提示之后显示屏幕下面的图片,param已经发送到radgrid的过滤器,当我调试时,FilterExpression准确得到一个值,radgrid也重新绑定,但它不会过滤。 / p>

enter image description here

更新2"代码工具提示":

在这个页面中,我使用了2个RadtooltipManager,一个用于网格行,一个用于列标题。

设计视图:

        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    </telerik:RadWindowManager>

    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
        <div>
            Keyword:<telerik:RadTextBox ID="rtbSearch" runat="server" Skin="Web20" Width="150px" EmptyMessage="Enter customer name..." ViewStateMode="Enabled"></telerik:RadTextBox>
            <telerik:RadComboBox ID="rcbProvince" Skin="Web20" runat="server" OnDataBound="rcbProvince_DataBound">
            </telerik:RadComboBox>
            Start
        <telerik:RadDatePicker ID="rdpStartDay" runat="server" ShowPopupOnFocus="True"></telerik:RadDatePicker>
            End
        <telerik:RadDatePicker ID="rdpEndDay" runat="server" ShowPopupOnFocus="True"></telerik:RadDatePicker>
            <telerik:RadButton ID="rbSearch" Text="Search" OnClientClicked="checkDate" runat="server" Skin="Web20" OnClick="rbSearch_Click"></telerik:RadButton>
            <div class="blank"></div>
            <div>
                <telerik:RadGrid ID="rgOrders" EnableLinqExpressions="false" AllowPaging="True" runat="server" AllowSorting="True" AllowMultiRowSelection="True" AutoGenerateColumns="False" GridLines="None" OnItemCreated="rgOrders_ItemCreated" OnPreRender="rgOrders_PreRender" OnItemDataBound="rgOrders_ItemDataBound" OnItemCommand="rgOrders_ItemCommand" PageSize="5" Skin="Web20" OnPageIndexChanged="rgOrders_PageIndexChanged" OnSortCommand="rgOrders_SortCommand" OnNeedDataSource="rgOrders_NeedDataSource">
                    <GroupingSettings CaseSensitive="false" />
                    <MasterTableView DataKeyNames="CustomerId" AllowMultiColumnSorting="true" AllowFilteringByColumn="true">
                        <SortExpressions>
                            <telerik:GridSortExpression FieldName="OrderDate" SortOrder="Descending" />
                        </SortExpressions>
                        <CommandItemSettings ExportToPdfText="Export to Pdf" />
                        <Columns>
                            <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn">
                            </telerik:GridClientSelectColumn>
                            <telerik:GridTemplateColumn AllowFiltering="false" HeaderText="No.">
                                <ItemTemplate>
                                    <%# (Container.DataSetIndex+1).ToString() %>
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle Font-Bold="True" HorizontalAlign="Center" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" DataField="Name" HeaderText="Customer Name" SortExpression="Name" UniqueName="Name">
                                <ItemTemplate>
                                    <asp:HyperLink ID="targetControl" runat="server" NavigateUrl='<%# Eval("OrderId","UpdateOrders.aspx?OrderId={0}") %>' Text='<%# Eval("Name") %>'></asp:HyperLink>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="OrderId" HeaderText="Order No" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" UniqueName="OrderID">
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle Font-Bold="True" HorizontalAlign="Center" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="OrderDate" HeaderText="Order Date" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" UniqueName="OrderDate">
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle HorizontalAlign="Center" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PaymentTypeName" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" ShowFilterIcon="false" HeaderText="Payment Type" UniqueName="PaymentTypeName">
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle HorizontalAlign="Center" />
                            </telerik:GridBoundColumn>   
                            <telerik:GridBoundColumn DataField="TotalAmount" DataType="System.String" HeaderText="TotalAmount" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" ShowFilterIcon="false" UniqueName="TotalAmount">
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle Font-Bold="True" HorizontalAlign="Center" />
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn DataField="IsClosed" ShowFilterIcon="false" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" HeaderText="IsClosed" SortExpression="IsClosed" UniqueName="IsClosed">
                                <ItemTemplate>
                                    <asp:Label ID="Label11" runat="server" Text='<%# Eval("IsClosed") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle Font-Bold="True" HorizontalAlign="Center" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="#" AllowFiltering="false">
                                <ItemTemplate>
                                    <asp:Button ID="btnXoa" runat="server" CommandArgument='<%# Eval("OrderId") %>' CommandName="DeleteOrder" OnClientClick="if(!confirm('Are you sure to delete?')) return false;" Text="X" />
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle HorizontalAlign="Center" />
                            </telerik:GridTemplateColumn>
                        </Columns>
                    </MasterTableView>
                    <FilterItemStyle HorizontalAlign="Center" />
                    <PagerStyle HorizontalAlign="Right" PageButtonCount="5" FirstPageText="First" FirstPageToolTip="" LastPageText="Last" LastPageToolTip="" NextPagesToolTip="" NextPageText="Next" NextPageToolTip="" PageSizeLabelText="" PrevPagesToolTip="" PrevPageText=" Previous" PrevPageToolTip="" EnableSEOPaging="True" />
                    <ClientSettings EnableRowHoverStyle="true">
                        <Selecting AllowRowSelect="True"></Selecting>
                    </ClientSettings>
                    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Web20" EnableImageSprites="True">
                    </HeaderContextMenu>
                </telerik:RadGrid>
            </div>
            <div class="blank"></div>
            <div class="left">
                <asp:Button ID="btnDelete" runat="server" OnClientClick="if(!confirm('Are you sure to delete?')) return false;" Text="Delete" OnClick="btnDelete_Click" />
                <telerik:RadButton ID="rbtnCLose" runat="server" Text="Close" Skin="Web20" OnClick="rbtnCLose_Click"></telerik:RadButton>
            </div>
        </div>
    </telerik:RadAjaxPanel>
    <telerik:RadToolTipManager ID="RadToolTipManager1" OffsetY="-1" HideEvent="LeaveTargetAndToolTip"
        Width="250" Height="100" runat="server" OnAjaxUpdate="OnAjaxUpdate" RelativeTo="Element"
        Position="MiddleRight">
    </telerik:RadToolTipManager>
    <telerik:RadToolTipManager ID="RadToolTipManager2" ShowDelay="1000" HideDelay="500" OffsetY="-1" HideEvent="ManualClose"
        Width="180" Height="150" runat="server" OnAjaxUpdate="OnAjaxUpdateHeader" RelativeTo="Element"
        Position="TopCenter">
    </telerik:RadToolTipManager>

代码背后:

protected void OnAjaxUpdate(object sender, ToolTipUpdateEventArgs e)
    {
        this.UpdateToolTip(e.Value, e.UpdatePanel);
    }
    protected void OnAjaxUpdateHeader(object sender, ToolTipUpdateEventArgs e)
    {
        this.UpdateToolTipHeader(e.Value, e.UpdatePanel);
    }
    private void UpdateToolTip(string elementID, UpdatePanel panel)
    {
        Control ctrl = Page.LoadControl("controls/CustomerDetails.ascx");
        ctrl.ID = "UcCustomerDetails";
        panel.ContentTemplateContainer.Controls.Add(ctrl);
        controls.CustomerDetails details = (controls.CustomerDetails)ctrl;
        details.CustomerId = elementID;
    }
    private void UpdateToolTipHeader(string elementID, UpdatePanel panel)
    {
        Control ctrl = Page.LoadControl("controls/TooltipCategory.ascx");
        ctrl.ID = "UcTooltipCategory";
        panel.ContentTemplateContainer.Controls.Add(ctrl);
        controls.TooltipCategory details = (controls.TooltipCategory)ctrl;
        details.HeaderText = elementID;
    }

Radgrid的ItemDatabound:

protected void rgOrders_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
        {
            Control target = e.Item.FindControl("targetControl");
            if (!Object.Equals(target, null))
            {
                if (!Object.Equals(this.RadToolTipManager1, null))
                {
                    this.RadToolTipManager1.TargetControls.Add(target.ClientID, (e.Item as GridDataItem).GetDataKeyValue("CustomerId").ToString(), true);
                }
            }
        }
        else if (e.Item.ItemType == GridItemType.Header)
        {
            GridHeaderItem item = (GridHeaderItem)e.Item;
            if (!Object.Equals(this.RadToolTipManager2, null))
            {
               this.RadToolTipManager2.TargetControls.Add(item.Cells[4].ClientID, "Name", true);
               this.RadToolTipManager2.TargetControls.Add(item.Cells[6].ClientID, "OrderDate", true);
               this.RadToolTipManager2.TargetControls.Add(item.Cells[7].ClientID, "PaymentTypeName", true);
               this.RadToolTipManager2.TargetControls.Add(item.Cells[8].ClientID, "TotalAmount", true);
               this.RadToolTipManager2.TargetControls.Add(item.Cells[9].ClientID, "IsClosed", true);
            }         
        }
    }

我遇到这个问题的方法是:当用户将鼠标悬停在标题上时,我会将列标题的文本发送到WebUserControl,它将返回具有不同值的列表项。之后,我设置初始过滤器并刷新此页面以获得结果。 重要:一切正常,只有TotalAmount列无效。

1 个答案:

答案 0 :(得分:1)

问题解决了。我浪费了很多时间:(。

问题是FilterExpression中的'Like'条件,它使数字列不能过滤。

rgOrders.MasterTableView.FilterExpression = "([" + filter.columnName + "] LIKE \'%" + filter.searchStrings + "%\') ";

我将上面的代码更改为:

rgOrders.MasterTableView.FilterExpression = "([" + filter.columnName + "] = \'" + filter.searchStrings + "\') ";

它适用于字符串列和数字列。