• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

GridView sort only to specified fields

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
nuritat
Asked:
nuritat
  • 3
  • 2
1 Solution
 
Easwaran ParamasivamCommented:
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
 
nuritatAuthor Commented:
Thats what I was looking for, but unfortunatly I have only "SortExpression" element in property list and not sortMode

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Easwaran ParamasivamCommented:
Above link contains solution for datagridview  
  dgvCol.SortMode = DataGridViewColumnSortMode.NotSortable

Change it accordingly for Gridview.

0
 
chandrasekar1Commented:
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
 
nuritatAuthor Commented:
perfect solution for gridview that doesn't have SortModa as property

thanks!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now