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

GridTemplateColumn & SortExpression

1 Answer 413 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jean-Yves
Top achievements
Rank 1
Jean-Yves asked on 05 Jan 2011, 05:33 PM
Hello, 

I have a small question, about the SortExpression in a GridTemplateColumn.
In fact, I have a SQL table [Action] and a table [PlanActionNiveauDeRealisation]. Like this an [Action] can have a lot of [PlanActionNiveauDeRealisation].

So, I put a RadGrid with all my [Actions] and in the last columns I put this : 
<telerik:GridTemplateColumn UniqueName="LastNiveau" HeaderText="Niveau de réalisation" >
                        <ItemTemplate>
                            <telerik:RadRating ID="ratingBar" runat="server" Orientation="Horizontal" ItemHeight="61px"
                                ItemWidth="11px" CssClass="ratingClass" OnRate="ratingBar_Rate" AutoPostBack="true">
                                <Items>
                                    <telerik:RadRatingItem Value="0" HoveredImageUrl="/images/Rating/Rating1/2h.png" HoveredSelectedImageUrl="/images/Rating/Rating1/2h.png"
                                        SelectedImageUrl="/images/Rating/Rating1/2s.png" ImageUrl="/images/Rating/Rating1/2.png" ToolTip="0 %" />
                                    <telerik:RadRatingItem Value="25" HoveredImageUrl="/images/Rating/Rating1/3h.png" HoveredSelectedImageUrl="/images/Rating/Rating1/3h.png"
                                        SelectedImageUrl="/images/Rating/Rating1/3s.png" ImageUrl="/images/Rating/Rating1/3.png" ToolTip="25 %" />
                                    <telerik:RadRatingItem Value="50" HoveredImageUrl="/images/Rating/Rating1/4h.png" HoveredSelectedImageUrl="/images/Rating/Rating1/4h.png"
                                        SelectedImageUrl="/images/Rating/Rating1/4s.png" ImageUrl="/images/Rating/Rating1/4.png" ToolTip="50 %" />
                                    <telerik:RadRatingItem Value="75" HoveredImageUrl="/images/Rating/Rating1/5h.png" HoveredSelectedImageUrl="/images/Rating/Rating1/5h.png"
                                        SelectedImageUrl="/images/Rating/Rating1/5s.png" ImageUrl="/images/Rating/Rating1/5.png" ToolTip="75 %" />
                                    <telerik:RadRatingItem Value="100" HoveredImageUrl="/images/Rating/Rating1/6h.png" HoveredSelectedImageUrl="/images/Rating/Rating1/6h.png"
                                        SelectedImageUrl="/images/Rating/Rating1/6s.png" ImageUrl="/images/Rating/Rating1/6.png" ToolTip="100 %" />
                                </Items>
                            </telerik:RadRating>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

In the ItemDataBound, I put : 
protected void RGPlanAction_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                var maxLength = 50;
                var dataItem = e.Item as GridDataItem;
                var myPlanAction = (Model.PlanAction)e.Item.DataItem;
 
                var myRadRating = (RadRating) dataItem["LastNiveau"].FindControl("ratingBar");
                myRadRating.Attributes.Add("IdPlanAction", myPlanAction.IdPlanAction.ToString());
                myRadRating.Attributes.Add("IndexRadGrid", e.Item.ItemIndex.ToString());
                var ndr = myPlanAction.PlanActionNiveauDeRealisation.LastOrDefault();
                if(ndr != null)
                {
                    myRadRating.Value = ndr.NiveauDeRealisation;   
                }
                else
                {
                    myRadRating.Value = 0;  
                }
            }
        }

Like this, it's perfect, I have a nice RadGrid with the last [PlanActionNiveauDeRealisation] of each [action].

Just, I would like to make some sorting with this last column : [lastNiveau], but i dunno what to put in the SortExpression...

Do you have any idea?


Thank you



1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 10 Jan 2011, 01:25 PM
Hi,

Please review the following help topic which elaborates on this matter:
http://www.telerik.com/help/aspnet-ajax/grdbasicsorting.html
http://www.telerik.com/help/aspnet-ajax/grdsortingexpressions.html

Regards,
Maria Ilieva
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Jean-Yves
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or