Solved

datagrid problem - sorting

Posted on 2004-09-02
5
247 Views
Last Modified: 2010-04-15
I have a problem with my DataGrid.
Afther I select sorting by anything else then id (which coincides with my default view), i get the new DataGrid layout, but then if i try to do anything with my DataGrid entries, i get wrong IDs.
The IDs I get alre from the old (default) DataGrid.

What am I missing?

code:
private void SortCommand(object source,System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
            {      
                  DataGrid1.DataSource = GetDSbySortExpr(int.Parse(e.SortExpression));
                  DataGrid1.DataBind();
            }

where GetDSbySortExpr connect to the database and returns a query according to my SortExpression:
 switch (SortExpression)
{
   case 0 : select...order by Id..
   case 1 : select...order by name...
}

TNX!
0
Comment
Question by:jurij
  • 3
5 Comments
 

Expert Comment

by:hunor_nam
ID: 11962637
Hm... how do you retrive the id-s? I mean from the grid (that's your problem, right?)
And is that the same querry? only different order by?
If so, it would be better to use dataView over the dataSet, so you would sort without going to the db...
but i really don't know you're context... are there many rows? do you HAVE to go to db?
0
 
LVL 10

Assisted Solution

by:123654789987
123654789987 earned 125 total points
ID: 11962656
U have to do a sort of the dataview

private void SortByColumns()
{
   // Get the DefaultViewManager of a DataTable.
   DataView myDataView = DataTable1.DefaultView;
   // By default, the first column sorted ascending.
   myDataView.Sort = "ID DESC";
}

Then rebind the dataview to the datagrid

0
 

Accepted Solution

by:
hunor_nam earned 125 total points
ID: 11962742
Yes exactly, if you dont need to go to the db than this is you're way.

Even more, i would recomend looking at the dataView class as it can easen you're work verry much.
You can even filter (for example) by seting the rowFilter (if i recall) property to a valid t-sql condition.

Please give feedback on what is that you acctually want to do.
0
 

Author Comment

by:jurij
ID: 11964912
Damn. I had a nasty bug in my code, that refilled my DataGrid every time Page_Load fired :/ No wonder i always recived data from default view :]

Tnx for all your help, I'll split the points.

One more thing before i close the thread. What is better.. To get sorted items from Database or to sort items from dataview? It probably depends on the amount of data beeing past from Database (if so, how many items). I'm currently working with less than 20 entries.

Thank you all.


0
 

Expert Comment

by:hunor_nam
ID: 11970721
HI Jurij.
I'm happy to hear you managed to sort things out.
For 20 records it's no use to go to the database every time...
How many it's safe? I actually can't say anything wise there... You should do some checking and see what's better.
Regard,
H.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
scanning dentists xray (the small ones) 3 53
Connection String 16 54
Install Problem 13 29
Need to start a web service from Visual Studio 2015 Pro 2 21
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question