Datagrid - Random order

P

Paul Evans

Hi,

I've created a datagrid which works fine accept the id field (the primary
key field) comes out in a random order. How do I get the fields to display
sequencially?

Thanks for your time

Paul Evans
 
K

Karl Seguin

Paul,
The order in which items appear is the order of the underlying datasource.
Therefore, you can either control the order from your SELECT/Sproc
statement, or by creating a DataView:

DataSet ds = GetMyData();
DataView dv = ds.tables[0].DefaultView;
dv.Sort = "MyPrimaryKeyColumn ASC";
myGrid.DataSource = dv;
myGrid.DataBind();

all this is assuming your datasource is a dataset/table.

Karl
 
T

tomBond

Hi, Paul.

Sort your data before you bring it into the grid. SQL has "ORDER B
customerID ASC".
If you dont't sort your data before, you can do it at next level.
I assume that your query gets the data into dataset, so this gives yo
the possibility to do some sorting and filtering before binding th
data to the grid. Datasets tables have an object called "DefaultView
(type dataview) which has a property "RowFilter". This takes a
SQL-string as an parameter, like "ORDER BY customerID ASC". Dataview i
the object that you bind to the grid, not the dataset. Check ADO.NE
documentation and you'll find correct syntax for these, as I threw thi
answer just by memory :)

-tom


-
tomBon
 

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

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top