我有一個Radgrid的頁面。一切都可以,直到我實現了一個自定義過濾器並根據會話設置默認過濾器。我在列標題上做了一個工具提示,允許用戶選擇濾波器radgrid的項目。Radgrid Telerik默認過濾器錯誤,列號
所有列的運行除 「總金額」 列好的。當我點擊工具提示上的項目時沒有任何反應。
代碼設置默認過濾器時,在工具提示(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控件還重新綁定,但它不過濾。
更新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列無法正常工作。
在您的代碼中的任何問題? 請從您的代碼中刪除IsPostback條件 – 2014-10-27 19:20:49
我試圖刪除IsPostBack,但它仍然沒有。其他的列運行正常。只有TotalAmount列不起作用。 – 2014-10-28 01:15:36
你可以請你幫我一個忙,因爲你已經使用usercontrol的工具提示?如果您將一個項目中的代碼上傳到aspx和ascx頁面並與我們分享鏈接,那將會很好嗎? – 2014-10-29 18:33:57