473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Datagrid - Random order

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
Nov 19 '05 #1
2 1347
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
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Paul Evans" <pa*********@btinternet.com> wrote in message
news:Oe**************@TK2MSFTNGP12.phx.gbl...
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

Nov 19 '05 #2

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
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is...
1
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current...
0
by: David Laub | last post by:
When I bind a collection to a DataGrid (with teh single statement DataBind), I love that the property names become the column names/values for the grid. But I HATE that the columns are (seemingly?)...
2
by: Gummy | last post by:
Hello All, I have a webpage that has two dropdown listboxes. Based on what is selected in these dropdown listboxes, it filters a DataGrid . That works fine. In the DataGrid , when I go to edit...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.