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

sorting

1 Answer 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Farshad heidary
Top achievements
Rank 1
Farshad heidary asked on 29 Apr 2010, 07:02 AM
hi guys

i have radgrid and in it i have just 1 column that format is  telerik:GridTemplateColumn.
now i want to add Sort By Price and sort By Name to this column

how i can do that?

tnx

here is my grid code

 <telerik:GridTemplateColumn UniqueName="column1" 
               AllowFiltering="false"  ShowSortIcon="false"   
                Groupable="false"     
                ItemStyle-Font-Names="tahoma" ItemStyle-Font-Size="8"    
                HeaderStyle-Font-Size="8" HeaderStyle-Font-Names="tahoma">  
              <ItemTemplate> 
              <table cellpadding="0" cellspacing="0"  width="100%" style="border-style: none; border-width: 0px;margin:0px;padding:0px" border="0"   
                      ID="tblProductContent" runat="server">  
              <tr > 
              <td style="width:105px" valign="top">  
               <asp:Image  
                  ImageUrl='<%# Eval("PicPath") %>' 
                  Width="100px" Height="100px" 
                   ID="imgProduct" runat="server" /> 
                     
              </td> 
 
              <td> 
                <table cellpadding="0" cellspacing="0"  width="100%" style="border-style: none; border-width: 0px;margin:0px;padding:0px" border="0"   
                <tr> 
                    <tr> 
                        <td valign="top">  
                            <asp:Label ID="Label1" runat="server" Font-Size="10"   
                                Text='<%# Eval("Title") %>'></asp:Label> 
                            <br /> 
                            <br /> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td valign="top">  
                            <div style="margin: 5px;padding:5px; background-color: #F8F8F8; border: 1px solid #DADADA;width:470px">  
                                <asp:Label ID="Label2" runat="server" Font-Size="8" ForeColor="#666666"   
                                    Text='<%# Eval("Des") %>'></asp:Label> 
                                <br /> 
                                <br /> 
                                <div ID="moreInfo" onclick='<%# "openWin("+Eval("ProductID")+")"%>'   
                                    style="cursor:pointer;color:Blue">  
                                    <asp:Label ID="Label3" runat="server"   
                                        Text="<%$ Resources:Resource, MoreInfo %>"></asp:Label> 
                                </div> 
                                <br /> 
                            </div> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td valign="top">  
                            <asp:Label ID="Label5" runat="server" ForeColor="Red"   
                                Text="<%$ Resources:Resource, Price %>"></asp:Label> 
                            <asp:Label ID="Label4" runat="server" Font-Size="7pt" ForeColor="Red"   
                                Text='<%# Eval("Cost") %>'></asp:Label> 
                            <br /> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td valign="top">  
                            <table> 
                                <tr> 
                                    <td> 
                                        <telerik:RadNumericTextBox ID="txtCount" runat="server"   
                                            EmptyMessage="<%$ Resources:Resource, Count %>"   
                                            EmptyMessageStyle-HorizontalAlign="Center" Font-Names="tahoma" Font-Size="8"   
                                            HoveredStyle-HorizontalAlign="Center" InvalidStyleDuration="100"   
                                            MaxValue="32760" MinValue="0" NegativeStyle-HorizontalAlign="NotSet"   
                                            ShowSpinButtons="True" Skin="Office2007" Type="Number" Width="80px">  
                                            <FocusedStyle HorizontalAlign="Center" /> 
                                            <HoveredStyle HorizontalAlign="Center" /> 
                                            <EmptyMessageStyle HorizontalAlign="Center" /> 
                                            <NegativeStyle HorizontalAlign="Center" /> 
                                            <EnabledStyle HorizontalAlign="Center" /> 
                                            <NumberFormat AllowRounding="True" DecimalDigits="0"   
                                                KeepNotRoundedValue="False" /> 
                                        </telerik:RadNumericTextBox> 
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"   
                                            ControlToValidate="txtCount" ErrorMessage="*"   
                                            ValidationGroup='<%# Eval("ProductID") %>'></asp:RequiredFieldValidator> 
                                    </td> 
                                    <td> 
                                        <asp:Button ID="btnAddToBasket" runat="server"   
                                            CommandArgument='<%# Eval("ProductID") %>' CommandName="AddToBasket"   
                                            Text="<%$ Resources:Resource, AddToBasket %>"   
                                            ValidationGroup='<%# Eval("ProductID") %>' /> 
                                    </td> 
                                </tr> 
                            </table> 
                        </td> 
                    </tr> 
                </tr> 
                   
                </table> 
              </td> 
              </tr> 
              </table> 
               <hr style="size:landscape;width:635px; color: #688CAF; opacity:0.4;filter:alpha(opacity=40)" /> 
 
              </ItemTemplate> 
 
 
 
<HeaderStyle Font-Names="tahoma" Font-Size="8pt" Width="15%"></HeaderStyle> 
<ItemStyle Font-Names="tahoma" Font-Size="8pt" Width="15%"></ItemStyle> 
              </telerik:GridTemplateColumn> 

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 29 Apr 2010, 08:37 AM
Hi,

I would suggest you to add the buttons for sorting in HeaderTemplate as shown below. Then set the CommandName as "Sort" and CommandArgument to corresponding field name in order to sort accordingly.

ASPX markup:
  
              <telerik:GridTemplateColumn UniqueName="column1" SortExpression="" AllowFiltering="false" 
                        ShowSortIcon="false" Groupable="false" ItemStyle-Font-Names="tahoma" ItemStyle-Font-Size="8" 
                        HeaderStyle-Font-Size="8" HeaderStyle-Font-Names="tahoma">


                        <HeaderTemplate> 
                            <asp:LinkButton ID="lnkSortByName" CommandName="Sort" CommandArgument="Title" 
                                runat="server">Sort By Name</asp:LinkButton> 
                            <asp:LinkButton ID="lnkSortByPrice" CommandName="Sort" CommandArgument="Cost" 
                                runat="server">Sort BY Price </asp:LinkButton> 
                        </HeaderTemplate>


                        <ItemTemplate> 
                            <table  ............. 
                                     ............. 
                             </table> 
                            <hr style="size: landscape; width: 635px; color: #688CAF; opacity: 0.4; filter: alpha(opacity=40)" /> 
                        </ItemTemplate> 
               </telerik:GridTemplateColumn> 
 

Hope the suggestion would help you. Feel free to share the comments.

Regards,
Princy.
Tags
Grid
Asked by
Farshad heidary
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or