Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GridView sort only to specified fields

Posted on 2011-09-20
6
Medium Priority
?
303 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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 …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

927 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