We help IT Professionals succeed at work.

Datagrid sorting in WebMatrix

redcoder asked
Medium Priority
Last Modified: 2012-06-21
I am using Web Matrix and had drag a datagrid to display the data based on the value entered in OrderID -TextField.

When user enter orderid in text box, the datagrid list out the selected item based on the OrderID..
But then I set the AllowSorting property for Datagrid... When display on the web, there is link on the datagrid header but it doesn't sort when I click that link on the header.
Watch Question

Depending on how you fill the datagrid, you need to handle the datagird sort event. A data source control can do it for you. But a DataTable would need to be sorted using a DataView, then rebound to the grid.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


I don't quite understand... Could you give simple example ?
How do you fill the DataGrid? That will allow me to provide a better example.
Otherwise you can look at: http://aspnet.4guysfromrolla.com/articles/052202-1.aspx


I am using the Select Data Method form the CODE panel in Web Matrix... Then choose the Table name and the Where condition... Finally select the DataSet and name the method as GetOrderDetails.

After that I bind the GetOrderDetails method with with :
Dim orderID as String
    orderID =TextBox2.Text
    DataGrid1.DataSource = GetOrderDetails(CInt(TextBox2.Text))

Then I set the property of Datagrid1 AllowSorting to TRUE

It is able to display the record but not able to sort when I click the link in the datagrid header


I set the AutoGeneratedColumn to True..

Did you read the article I mentioned? It contains everything you need to sort. Be sure to read Part 2 of the article as it contains some of the info you need.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.