Hi guys,
I need help with sorting a customised GridTemplateColumn. The column snippet is shown below:
The column is used to display names either as a hyperlink or a simple label depending on the user's access rights. The main problem I have is that the values for these controls are generated at RadGrid's Item_Created event where it concatenates 2 strings (i.e. GivenNames & Surname) and binds the final output to the controls. See snippet below:
What I would like to do, is to be able to sort the column by its final output. but I'm not sure how to go about doing it. Please help!
Regards
Jonathan
I need help with sorting a customised GridTemplateColumn. The column snippet is shown below:
| <telerik:GridTemplateColumn UniqueName="NameCommandColumn" AllowFiltering="False" |
| ItemStyle-Width="150" HeaderStyle-Width="150" ShowSortIcon="true" > |
| <HeaderTemplate>Name</HeaderTemplate> |
| <ItemTemplate> |
| <asp:HyperLink ID="hlnkContactName" runat="server"></asp:HyperLink> |
| <asp:Label ID="lblContactName" runat="server"></asp:Label> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
The column is used to display names either as a hyperlink or a simple label depending on the user's access rights. The main problem I have is that the values for these controls are generated at RadGrid's Item_Created event where it concatenates 2 strings (i.e. GivenNames & Surname) and binds the final output to the controls. See snippet below:
| protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| if (e.Item is GridDataItem) |
| { |
| //Check the user's permissions. if the user has edit permissions then allow edit. |
| if (SecurityHelper.IsAllowedTo("Modify","PhoneList")) |
| { |
| #region Instantiate Name link |
| HyperLink hlnkContactName = (HyperLink)e.Item.FindControl("hlnkContactName"); |
| if (hlnkContactName != null) |
| { |
| Label lblContactName = (Label)e.Item.FindControl("lblContactName"); |
| if (lblContactName != null) |
| lblContactName.Visible = false; |
| hlnkContactName.Attributes["href"] = "#"; |
| hlnkContactName.Attributes["onclick"] = string.Format("return ShowForm('{0}')", |
| Constants.URL_PHONELISTEDITOR + "?" + Constants.QUERYSTRING_PARTYID + "=" + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["PartyId"].ToString()); |
| hlnkContactName.Text = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["GivenNames"].ToString() +" "+ |
| e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Surname"].ToString(); |
| } |
| #endregion |
| } |
| else |
| { |
| #region Instantiate Name Label |
| Label lblContactName = (Label)e.Item.FindControl("lblContactName"); |
| if (lblContactName != null) |
| { |
| HyperLink hlnkContactName = (HyperLink)e.Item.FindControl("hlnkContactName"); |
| if (hlnkContactName != null) |
| hlnkContactName.Visible = false; |
| lblContactName.Visible = true; |
| lblContactName.Text = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["GivenNames"].ToString() +" "+ |
| e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Surname"].ToString(); |
| } |
| #endregion |
| } } |
| } |
What I would like to do, is to be able to sort the column by its final output. but I'm not sure how to go about doing it. Please help!
Regards
Jonathan