• A2ZMenu.Com
Loading
  • Home
  • Blogs
    • AJAX
    • ASP.NET
    • BI
    • CSharp
    • JavaScript
    • LINQ
    • Miscellaneous
    • SQL
    • SharePoint
    • Silverlight
    • WCF
  • Tutorials
    • HTML5
    • ASP.NET 4.0
    • CSharp
    • SharePoint
    • SQL Function
  • Online Exam
    • ASP.NET
    • LINQ
    • Silverlight
    • SQL
    • JavaScript
    • SharePoint
  • Forum
  • Utility
  • Fun @ Work
    • Appraisal
    • Funny Images
    • Funny Puzzle
    • Miscellaneous
    • Motivating Stories
  • Wiki
  • Contact Us
  • AJAX
  • ASP.NET
  • BI
  • CSharp
  • JavaScript
  • LINQ
  • Miscellaneous
  • SQL
  • SharePoint
  • Silverlight
  • WCF

Test Your Skill

Show/Hide
 Q. Out of Boxing and Unboxing which one is implicit?
View all questions...
Datagrid TemplateColumn Sorting in Silverlight 3
Tweet
mail-image

Hello Folks,

Want to create Silverlight datagrid with sorting funtionality. You don't need to write 100 lines of code to achieve this. Thisis because when you bound collection that implements IList, Silverlight will internally create ListCollectionView to provide sorting functionality. The only thing that you need to do is to set the CanUserSort property of the column to true. By default each column for which CanUserSort attribute is set to true is sorted by the property which is bind to the Column.

<data:DataGridTextColumn Header="FirstName" Width="SizeToHeader"

                    Binding="{Binding FirstName}" CanUserSort="true" />

Till this point you don't need to worry much, but have you ever faced a scenario where you had a DataGrid with custom column with CanUserSort set to true, but still sorting did not work. The reason being in case of standard grid the property used for binding and sorting is same. But when you create a custom column there is no way for the column to figure out on what basis the sorting should occur, as a result the sorting does not work. In this case if you want to enable sorting, you need to assign the property nameto SortMemberPath attribute of DataGridTemplateColumn.

<data:DataGridTemplateColumn Header="Name" CanUserSort="true" SortMemberPath="DisplayName">

 <data:DataGridTemplateColumn.CellTemplate>

  <DataTemplate>

    <TextBlock Text="{Binding DisplayName}"/>

  </DataTemplate>

 </data:DataGridTemplateColumn.CellTemplate>

</data:DataGridTemplateColumn>


Happy Coding :)



Add Comment

Comment
Name
 (Required)
E-mail (Privacy assured)
 (Required)

Poll of the Day

  Who is best CEO so far?
 
 
 

Related Contents

Online Test Papers

  • ASP.NET
  • JavaScript
  • LINQ
  • SharePoint
  • Silverlight
  • SQL

Related Tutorials

  • HTML 5 Tutorial
  • SharePoint Best Practice
  • ASP.NET 4.0 Tutorials

Connect with Facebook

Top Blogs

  • SharePoint 2010 Model Dialog
  • Validation of viewstate MAC failed. If this application is hosted...
  • Silverlight: ListBox with CheckBox
  • Creating a Windows Service in C#
  • Using InstallUtil to install/uninstall service
  • How to call webservice using Ajax or JavaScript
  • LINQ to SQL Best Practice
  • The contract name could not be found in the list of contracts implemented by the service
  • Calling JavaScript function from C#
Blogs
  • AJAX
  • ASP.NET
  • BI
  • CSharp
  • HTML
  • JavaScript
  • LINQ
  • SQL Server
  • SharePoint
  • Silverlight
Tutorials
  • HTML5
  • ASP.NET 4.0
  • CSharp
  • SharePoint
  • SQL Server
Online Examinations
  • ASP.NET
  • LINQ
  • SQL Server
  • JavaScript
  • SharePoint
Online Utilities
  • Age Calculator
  • Happy Birthday Wisher
  • Independence Day Wisher
  • URL Encoder Decoder
  •  
Fun @ Work
  • Appraisal
  • Funny Images
  • Funny Puzzle
  • Miscellaneous
  • Motivating Stories
A2ZMenu © 2012 Home | Contact Us | Privacy Policy | Connect with Facebook | Follow us on Twitter