I'm encountering an issue where controls in the HeaderTemplate do not seem to be updated via AJAX callbacks from the RadGrid.
ASP.NET version: 3.5
OS: Windows XP SP2
Browser: IE 7
RadControls version: Q1 2009
Language: C#
I have a template column that includes 5 "virtual" columns both within the ItemTemplate, EditItemTemplate and the HeaderTemplate for the column. I'm attempting to implement sorting on each of these "virtual" columns in a like manner to the other columns using the default RadGrid sorting functionality. Currently I'm attempting to use Labels to indicate the sort direction for each of these columns. One indicating ASC, and one DESC, with the idea of simply changing visibility to visually indicate the sort order for the column. I have an entry for the RadGrid within the RadAjaxManagerProxy to update the Label controls in question. However, while the event is raised properly and I can see change in visisbility applied to the Label in question, the change does not seem to be pushed down to the Label control within the HeaderTemplate from the AJAX call.
Relevant ASPX Code
| <telerik:RadAjaxManagerProxy ID="EntityMainAjaxProxy" runat="server"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="EandP_Details"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="EandP_Details" /> |
| <telerik:AjaxUpdatedControl ControlID="rdgridAllCFCs" /> |
| <telerik:AjaxUpdatedControl ControlID="rdgridSoloCFC" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| <telerik:AjaxSetting AjaxControlID="rdgridAllCFCs"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="rdgridAllCFCs" /> |
| <telerik:AjaxUpdatedControl ControlID="lblAsc_PTI" /> |
| <telerik:AjaxUpdatedControl ControlID="lblDesc_PTI" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| <telerik:AjaxSetting AjaxControlID="rdgridSoloCFC"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="rdgridSoloCFC" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManagerProxy> |
| ... |
| <telerik:RadGrid ID="rdgridAllCFCs" runat="server" AllowPaging="false" GridLines="None" Skin="Office2007" AllowSorting="true" |
| OnNeedDataSource="rdgridAllCFCs_NeedDataSource" OnItemDataBound="rdgridAllCFCs_ItemDataBound" OnItemCommand="rdgridAllCFCs_ItemCommand"> |
| <ClientSettings EnablePostBackOnRowClick="true"></ClientSettings> |
| <MasterTableView AutoGenerateColumns="false" EditMode="InPlace" ShowFooter="true" CellPadding="0" CellSpacing="0"> |
| <Columns> |
| <telerik:GridTemplateColumn SortExpression="Entity" HeaderText="Entity" UniqueName="Entity" ShowSortIcon="true" HeaderButtonType="TextButton"> |
| <ItemTemplate> |
| <asp:Label ID="lblEntity" runat="server"></asp:Label> |
| </ItemTemplate> |
| <ItemStyle HorizontalAlign="Left" /> |
| <FooterTemplate> |
| <asp:Label ID="lblTotal" runat="server">Total</asp:Label> |
| </FooterTemplate> |
| <FooterStyle HorizontalAlign="Right" Font-Bold="true" BackColor="#d3dbe9" Font-Size="Larger" BorderWidth="2px" BorderColor="Black" BorderStyle="Solid"/> |
| <HeaderStyle HorizontalAlign="Center" /> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn SortExpression="CC_Name" HeaderText="Country" UniqueName="CC_Name" ShowSortIcon="true" HeaderButtonType="TextButton"> |
| <ItemTemplate> |
| <asp:Label ID="lblCountry" runat="server"></asp:Label> |
| </ItemTemplate> |
| <ItemStyle HorizontalAlign="Left" /> |
| <FooterTemplate> |
| |
| </FooterTemplate> |
| <FooterStyle BackColor="Gray" BorderWidth="2px" BorderColor="Gray" BorderStyle="Solid"/> |
| <HeaderStyle HorizontalAlign="Center" /> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn SortExpression="C_Name" HeaderText="Functional<br/>Currency" UniqueName="C_Name" ShowSortIcon="true" HeaderButtonType="TextButton"> |
| <ItemTemplate> |
| <asp:Label ID="lblCurrency" runat="server"></asp:Label> |
| </ItemTemplate> |
| <ItemStyle HorizontalAlign="Left" /> |
| <FooterTemplate> |
| |
| </FooterTemplate> |
| <FooterStyle BackColor="Gray" BorderWidth="2px" BorderColor="Gray" BorderStyle="Solid"/> |
| <HeaderStyle HorizontalAlign="Center" /> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn SortExpression="SpotRate" HeaderText="Current Spot Rate" UniqueName="SpotRate" ShowSortIcon="true" HeaderButtonType="TextButton"> |
| <ItemTemplate> |
| <asp:Label ID="lblSpot" runat="server"></asp:Label> |
| </ItemTemplate> |
| <ItemStyle HorizontalAlign="Right" /> |
| <FooterTemplate> |
| |
| </FooterTemplate> |
| <FooterStyle BackColor="Gray" BorderWidth="2px" BorderColor="Gray" BorderStyle="Solid"/> |
| <HeaderStyle HorizontalAlign="Center" /> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn > |
| <HeaderTemplate> |
| <table style="text-align: center; border-color: Black; border-style:solid; border-width:thin; width:380px; margin: 0" cellspacing="0" cellpadding="2"> |
| <tr> |
| <td colspan="3" style="border-color: Black; border-right-style:solid; border-right-width:thin; border-bottom-style:solid; border-bottom-width:thin; text-align:center; width: 210px"> |
| 959(c)(3) |
| </td> |
| <td style="border-right-style:solid; border-right-width: 1px; border-right-color:Black; width:70px; vertical-align:bottom" rowspan="2"> |
| <asp:LinkButton ID="btnPTISort" runat="server" ToolTip="Click here to sort" CommandName="TemplateSort" CommandArgument="PTI">PTI<br />(US$)</asp:LinkButton> |
| <asp:Label ID="lblAsc_PTI" runat="server" Visible="false">></asp:Label> |
| <asp:Label ID="lblDesc_PTI" runat="server" Visible="false"><</asp:Label> |
| </td> |
| <td style="width:90px; vertical-align:bottom" rowspan="2"> |
| <asp:LinkButton ID="btnFXSort" runat="server" ToolTip="Click here to sort" CommandName="TemplateSort" CommandArgument="FX">Built-in FX<br />Gain/(Loss)<br />(US$)</asp:LinkButton> |
| <asp:Label ID="lblAsc_FX" runat="server" Visible="false">></asp:Label> |
| <asp:Label ID="lblDesc_FX" runat="server" Visible="false"><</asp:Label> |
| </td> |
| </tr> |
| <tr> |
| <td style="border-right-style:solid; border-right-width: 1px; border-right-color:Black; width:70px; vertical-align:bottom"> |
| <asp:LinkButton ID="btnEandPUSSort" runat="server" ToolTip="Click here to sort" CommandName="TemplateSort" CommandArgument="EandPUS">E & P<br />(US$)</asp:LinkButton> |
| <asp:Label ID="lblAsc_EandPUS" runat="server" Visible="false">></asp:Label> |
| <asp:Label ID="lblDesc_EandPUS" runat="server" Visible="false"><</asp:Label> |
| </td> |
| <td style="border-right-style:solid; border-right-width: 1px; border-right-color:Black; width:70px; vertical-align:bottom"> |
| <asp:LinkButton ID="btnTaxesUSSort" runat="server" ToolTip="Click here to sort" CommandName="TemplateSort" CommandArgument="TaxesUS">Taxes<br />(US$)</asp:LinkButton> |
| <asp:Label ID="lblAsc_TaxesUS" runat="server" Visible="false">></asp:Label> |
| <asp:Label ID="lblDesc_TaxesUS" runat="server" Visible="false"><</asp:Label> |
| </td> |
| <td style="border-color: Black; border-right-style:solid; border-right-width:thin; width:70px; vertical-align:bottom"> |
| <asp:LinkButton ID="btnEffRateSort" runat="server" ToolTip="Click here to sort" CommandName="TemplateSort" CommandArgument="EffRate" >Effective<br />Rate</asp:LinkButton> |
| <asp:Label ID="lblAsc_EffRate" runat="server" Visible="false">></asp:Label> |
| <asp:Label ID="lblDesc_EffRate" runat="server" Visible="false"><</asp:Label> |
| </td> |
| </tr> |
| </table> |
| </HeaderTemplate> |
| <HeaderStyle HorizontalAlign="Left" Width="370px"/> |
| <ItemTemplate> |
| <table style="text-align:center; width:380px; border-style: none; margin:0" cellspacing="0" cellpadding="2"> |
| <tr> |
| <td style="text-align:right; width:70px; border-style:none"> |
| <asp:Label ID="lblUSD" runat="server">1,260</asp:Label> |
| </td> |
| <td style="text-align:right; width:70px; border-style:none"> |
| <asp:Label ID="lblTaxesUSD" runat="server">350</asp:Label> |
| </td> |
| <td style="text-align:right; width:70px; border-style:none"> |
| <asp:Label ID="lblEffRate" runat="server">27.78%</asp:Label> |
| </td> |
| <td style="text-align:right; width:70px; border-style:none"> |
| <asp:Label ID="lblPTIUSD" runat="server">715</asp:Label> |
| </td> |
| <td style="text-align:right; width:90px; border-style:none"> |
| <asp:Label ID="lblGLUSD" runat="server">59</asp:Label> |
| </td> |
| </tr> |
| </table> |
| </ItemTemplate> |
| <ItemStyle HorizontalAlign="Left" Width="370px"/> |
| <FooterTemplate> |
| <table style="text-align:center; width:380px; border-style: none" cellspacing="0" cellpadding="2"> |
| <tr> |
| <td style="text-align:right; width:70px; border-style:none"> |
| <asp:Label ID="lblTotalUSD" runat="server">1,260</asp:Label> |
| </td> |
| <td style="text-align:right; width:70px; border-style:none"> |
| <asp:Label ID="lblTotalTaxesUSD" runat="server">350</asp:Label> |
| </td> |
| <td style="text-align:right; width:70px; border-style:none"> |
| <asp:Label ID="lblTotalEffRate" runat="server">27.78%</asp:Label> |
| </td> |
| <td style="text-align:right; width:70px; border-style:none"> |
| <asp:Label ID="lblTotalPTIUSD" runat="server">715</asp:Label> |
| </td> |
| <td style="text-align:right; width:90px; border-style:none"> |
| <asp:Label ID="lblTotalGLUSD" runat="server">59</asp:Label> |
| </td> |
| </tr> |
| </table> |
| </FooterTemplate> |
| <FooterStyle Width="370px" Font-Bold="true" Font-Size="Larger" BackColor="#d3dbe9" BorderWidth="2px" BorderColor="Black" BorderStyle="Solid"/> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
================================================================================================
Relevant C# Code
| protected void rdgridAllCFCs_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| switch (e.CommandName) |
| { |
| case "TemplateSort": |
| LinkButton btn = e.Item.FindControl("btn" + e.CommandArgument.ToString() + "Sort") as LinkButton; |
| if (btn != null) |
| SortTemplateColumn(btn, e.CommandArgument.ToString()); |
| break; |
| default: |
| break; |
| } |
| } |
| private void SortTemplateColumn(LinkButton btn, string fieldName) |
| { |
| Label up = btn.Parent.FindControl("lblAsc_" + fieldName) as Label; |
| Label down = btn.Parent.FindControl("lblDesc_" + fieldName) as Label; |
| GridSortOrder sortDirection; |
| GridSortExpression newSort = new GridSortExpression(); |
| newSort.FieldName = fieldName; |
| if ((up == null) || (down == null)) |
| return; //Can't proceed without up and down indicators |
| if ((up.Visible == false) && (down.Visible == false)) |
| sortDirection = GridSortOrder.None; |
| else if (up.Visible == true) |
| sortDirection = GridSortOrder.Ascending; |
| else |
| sortDirection = GridSortOrder.Descending; |
| switch (sortDirection) |
| { |
| case GridSortOrder.None: |
| newSort.SortOrder = GridSortOrder.Ascending; |
| up.Visible = true; |
| down.Visible = false; |
| break; |
| case GridSortOrder.Ascending: |
| newSort.SortOrder = GridSortOrder.Descending; |
| up.Visible = false; |
| down.Visible = true; |
| break; |
| case GridSortOrder.Descending: |
| newSort.SortOrder = GridSortOrder.None; |
| up.Visible = false; |
| down.Visible = false; |
| break; |
| } |
| rdgridAllCFCs.MasterTableView.SortExpressions.AddSortExpression(newSort); |
| rdgridAllCFCs.Rebind(); |
| } |