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

GridHyperLinkColumn sorting behivour

8 Answers 290 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 30 Aug 2011, 03:48 AM
Hello.

I am trying to sort a RadGrid by GridHyperLinkColumn . I enabled the sorting and created sorting expression.

I want to make the header clickable in order to change it from ascending/descending  order .
however I cant make the header of the GridHyperLinkColumn clickable  . Can somebody offer me a solution? It does work on theGridBoundColumn  when I enable sorting .

Also after sorting ,the style of the header is changed  . Is there any way to stop it ?

Thank you

Joe 

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Aug 2011, 04:52 AM
Hello Joseph,

In order to enable sorting for GridHyperLinkColumn you should set appropriate SortExpression values for those columns. Check the following help documentation which explains more about this.
Sorting for GridHyperLinkColumn/GridTemplateColumn.

Thanks,
Princy.
0
Joseph
Top achievements
Rank 1
answered on 30 Aug 2011, 05:45 AM
Thank you for you answer.

I did what was explained in this link. It doesn't work ,
0
Joseph
Top achievements
Rank 1
answered on 30 Aug 2011, 07:19 AM
here is my code if it helpes
  
  <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"  AllowPaging="true"
        OnPreRender="RadGrid1_PreEnder" EnableViewState="true" 
    AllowAutomaticDeletes="false" 
       onitemcreated="RadGrid1_ItemCreated"
        CellSpacing="0" GridLines="None"   Skin="Default"  ShowFooter="true"
        EnableEmbeddedSkins="false" OnDeleteCommand="RadGrid1_DeleteCommand" 
        onneeddatasource="RadGrid1_NeedDataSource"
    onitemdatabound="RadGrid1_ItemDataBound"
        onsortcommand="RadGrid1_SortCommand1">          
  
 <SortingSettings  />
 <PagerStyle Mode="NextPrevAndNumeric"  CssClass="DataGridPager"/>
<MasterTableView  AllowAutomaticDeletes="false"   AutoGenerateColumns ="false" AllowSorting="true" AllowPaging="true" PageSize="1">  
<PagerStyle Mode="NumericPages" CssClass="DataGridPager" />
   
<Columns>
<telerik:GridTemplateColumn SortExpression="investor_name"  ItemStyle-Width="247px" UniqueName="investor_name" HeaderButtonType="PushButton">
    <HeaderTemplate>
      <asp:Button id="Button1" runat="server"
         Text="Investor Name"
         Title="Investor Name"
         CommandName='Sort'
         CommandArgument='investor_name' />
    </HeaderTemplate>
    <ItemTemplate>
    <asp:HyperLink ID="lnkInvestorName"  runat="server" 
    DataNavigateUrlFormatString=""  >
    </asp:HyperLink>
    </ItemTemplate>
    </telerik:GridTemplateColumn>                                                           
                            
                            <telerik:GridTemplateColumn UniqueName="model_alignment" HeaderTooltip="Alignment to model portfolio" HeaderText="M" 
                                ItemStyle-Width="25px"
                                 <ItemTemplate>
                                <asp:HyperLink ID="lnkModelAligment" runat="server"></asp:HyperLink>
                                </ItemTemplate>                                                                                      
                            </telerik:GridTemplateColumn >                                                      
                             <telerik:GridTemplateColumn   UniqueName="compliance_status" ItemStyle-Width="25" HeaderTooltip="Compliance status" HeaderText="C" >                              
                                <ItemTemplate>
                                        <asp:HyperLink ID="lnkComplianceStatus" runat="server"></asp:HyperLink>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn UniqueName="cash_value" DataField="cash_value"
                                DataFormatString="{0:###,###,##0.00}" ItemStyle-Width="80px" HeaderText="Cash Holdings" ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right"
                                 HeaderTooltip="Cash Holdings" >                                                                                                                                                      
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn UniqueName="investment_holdings"  ItemStyle-Width="110px"
                            HeaderText="Investment Holdings" ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right">                                                                                                             
                             </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="portfolio_value" UniqueName="portfolio_value"  HeaderText="Total Portfolio Value"                        
                                DataFormatString="{0:###,###,##0.00}" ItemStyle-Width="115px" ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right">                                                                                                                           
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn UniqueName="model_portfolio"
                            ItemStyle-Width="130px" HeaderText="Model Portfolio">                               
                              <ItemTemplate>
                                <asp:HyperLink ID="lnkModelPortfolio" runat="server"></asp:HyperLink>
                                </ItemTemplate>   
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="compliance_template" ItemStyle-Width="130px" HeaderText="Compliance Template" >                                                                                   
                                <ItemTemplate>
                                <asp:HyperLink ID="lnkComplianceTemplate" runat="server"></asp:HyperLink>
                                </ItemTemplate>        
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="actions" ItemStyle-Width="100px" HeaderText ="Actions">                             
                            <ItemTemplate>
                             <asp:HyperLink ID="lnkCompliancee" runat="server" ></asp:HyperLink>
                             <asp:HyperLink ID="lnkDel" runat="server"></asp:HyperLink>
                             <asp:HyperLink ID="lnkReb" runat="server"></asp:HyperLink>
                             <asp:HyperLink ID="lnkPeModel" runat="server"></asp:HyperLink>
                            </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn  Display="false" UniqueName="can_delete">                              
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="investor_id" Display="false"   HeaderText="investor_id"
                                UniqueName="investor_id">                                                             
                            </telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings  >
<ClientEvents />
 <Selecting   />
</ClientSettings>
 
</telerik:RadGrid>


0
Joseph
Top achievements
Rank 1
answered on 30 Aug 2011, 11:48 PM
Any Ideas ?? 

Still haven't figured it out 
0
Andrey
Telerik team
answered on 01 Sep 2011, 02:17 PM
Hello Joseph,

Please note that when using GridHyperLinkColumn you set value to the DataTextField property and to the SortExpression property. Based on the value of these properties the grid knows which field to sort. When using ASP hyperlink control in GridTemplateColumn such property is not provided. So the grid does not know based on what field to sort. On the other hand GridTemplateColumn provides the SortExpression property as well which value should match the data field you want to sort on (typically the field a control in the template is bound to).
For more information you could review in details this online help.

Kind regards,
Andrey
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Joseph
Top achievements
Rank 1
answered on 02 Sep 2011, 01:28 AM
Hello Andrew 

Thank you for you response.

Have a look at my code , it does exactly what was written in the article.

Still could not make the header Clickable , it seems like a bug in the Rad grid.
Any other Ideas?

Thank you

Joe


0
Joseph
Top achievements
Rank 1
answered on 02 Sep 2011, 02:14 AM
Hello

I found what was causing the problem .

Basically because  i was formatting the header text in the Code behind it caused the header of the GridHyperLinkCoulmn to be unclickable .
However I do need to format the header of the text in the  Code behind.
 Any ideas?



 

0
Joseph
Top achievements
Rank 1
answered on 02 Sep 2011, 02:23 AM
Tags
Grid
Asked by
Joseph
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Joseph
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or