Hi,I wan to sort my added record on the top of datagridview.I had try a few way to sort it but it no function."attn_id"is a primary key in database.

using (TMPB_attn_DAL dalObj = new TMPB_attn_DAL())
                {
                    dataGridView1.DataSource = dalObj.GetRecords().Cast<TMPB_attn>().ToList();
                    dataGridView1.Refresh();
                    dataGridView1.Sort(dataGridView1.Columns["attn_id"], ListSortDirection.Descending); 
                }

when i run the above code it show out error!Datagridview control must be bound to an iBindingList object to be sorted

how can i sort the record?

use order by attn_id desc in your query.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.