Solved

GridView sort only to specified fields

Posted on 2011-09-20
6
252 Views
Last Modified: 2012-05-12
Hi,

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?
0
Comment
Question by:nuritat
  • 3
  • 2
6 Comments
 
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.

0
 

Author Comment

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

0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36565876
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 16

Expert Comment

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

Change it accordingly for Gridview.

0
 
LVL 3

Accepted Solution

by:
chandrasekar1 earned 500 total points
ID: 36565925
nuritat,
i think you are talking about asp.net 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.ApplyStyle(s); 
                    tc.Attributes.Add("onclick","return false;"); 
                } 
            } 
        } 
    } 
 
}

Open in new window


ref link
http://forums.asp.net/t/1491465.aspx/1
0
 

Author Closing Comment

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

thanks!!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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 …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now