Cannot sort DataGrid using DefaultView?

B

Bill Todd

I have a simple Web app using the Northwind database. I have a typed
dataset that contains the Suppliers and Products tables. I need to
sort and filter the Products table. For reasons that are irrelevant to
this problem I cannot use a DataView component.

My WebForm contains the following code, however, after this code
executes the Product records in the DataGrid are not sorted by
ProductName. I have also tried setting the DataView's RowFilter
property and that does not work either. There are no error messages.

private DataView productDataView;
productDataView = northwindDataSet1.Tables["Products"].DefaultView;
productDataView.Sort = "ProductName";
productGrid.DataBind();

The properties of the DataGrid are:

DataSource = northwindDataSet1
DataMember = Products
DataKeyField = ProductId

I have also tried the following version of the code without success.

private DataView productDataView;
productDataView = northwindDataSet1.Tables["Products"].DefaultView;
productDataView.Sort = "ProductName";
productGrid.DataSource = productDataView;
productGrid.DataBind();

What do I have to do to get the DefaultView to work?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,135
Messages
2,570,787
Members
47,342
Latest member
KelseyK737

Latest Threads

Top