GridView sort only to specified fields

Posted on 2011-09-20
Last Modified: 2012-05-12

When I turn allow sorting to true, I get sort to all fields,
how can I make the sort option onlt to some fields and to others not?
Question by:nuritat
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36565843
By setting the DataGridViewColumn.SortMode property you can disable the ability for the user to sort on the given column. You can use Visual Studio to set this property by right-clicking on the DataGridView and choosing the Edit Columns option. Next select the column that you want to disable sorting for and set the SortMode property to NotSortable.


Author Comment

ID: 36565864
Thats what I was looking for, but unfortunatly I have only "SortExpression" element in property list and not sortMode

LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36565876
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36565884
Above link contains solution for datagridview  
  dgvCol.SortMode = DataGridViewColumnSortMode.NotSortable

Change it accordingly for Gridview.


Accepted Solution

chandrasekar1 earned 500 total points
ID: 36565925
i think you are talking about Gridview, if yes then check the below code

protected void gdvDataViewer_PreRender1(object sender, EventArgs e) 
    Style s = new Style(); 
    s.ForeColor = System.Drawing.Color.Red; 
    s.Width = 200; 
    if (gdvDataViewer.AllowSorting) 
        foreach (TableCell tc in gdvDataViewer.HeaderRow.Cells) 
            if (tc.HasControls()) 
                LinkButton lb = (LinkButton)tc.Controls[0]; 
                if (lb != null && lb.Text.Equals("CoumnNmae")) // your column to make unsortable 
                    tc.Attributes.Add("onclick","return false;"); 

Open in new window

ref link

Author Closing Comment

ID: 36566646
perfect solution for gridview that doesn't have SortModa as property


Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question