Solved

GridView sort only to specified fields

Posted on 2011-09-20
6
265 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

943 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

16 Experts available now in Live!

Get 1:1 Help Now