 |
| ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 4th, 2006, 01:26 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Numeric sorting in dataview
Now I got another issue to solve.
Recently in my application I had to sort the dataset on various feilds.
I could very well do with following commands.
dSet.Tables[0].DefaultView.Sort = "FeildName ASC"
Things work well for string feilds.
But when it is a numeric feild (Haven't checked with other datatypes) I could not get the sorting porperly..
For eg..
if the search returned: 1,20,11,2,7,8,10
the sort on dataview will be : 1,10,11,2,23,7,8
And I was looking for something like : 1,2,7,8,10,11,23
Is there any solution for this.
|
|

February 4th, 2006, 01:46 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Coding is correct. I think these numbers are being sorted as a string. check whether you have taken the datatype of datafield as integer or long. If not try this and tell me what happens....
Tell me how you resolve this problem. All the best.
Gaurav
|
|

February 4th, 2006, 05:11 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The feild is already an integer type.
It is the COUNT of records that is returned in that query.
|
|

February 4th, 2006, 06:33 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I dont know why it is not working ...Will u send me the coding for it ...may be there is something wrong in it ...
|
|

February 6th, 2006, 12:42 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Code:
Session["sortExpProperty"] = e.SortExpression;
if((string)Session["sortExpPropertyOrder"]=="ASC")
Session["sortExpPropertyOrder"] = "DESC";
else
Session["sortExpPropertyOrder"] = "ASC";
SqlCommand cmdPropertyList;
cmdPropertyList = new SqlCommand();
cmdPropertyList.CommandText="spAdminPropertyAddedToTravelKit";
cmdPropertyList.CommandType = CommandType.StoredProcedure;
DataSet dSetPropertyList = objMisc.funcExecuteCommandDataSet(cmdPropertyList);
if(dSetPropertyList.Tables[0].Rows.Count>0)
dSetPropertyList.Tables[0].DefaultView.Sort = Session["sortExpProperty"] + " " + Session["sortExpPropertyOrder"];
dGridProperty.DataSource = dSetPropertyList.Tables[0].DefaultView;
dGridProperty.DataBind();
And the stored procedure used is
Code:
CREATE PROCEDURE spAdminPropertyAddedToTravelKit
AS
SELECT
[tblProperties].[PropertyID],
[tblProperties].[PropertyName],
[tblProperties].[Region],
[tblProperties].[PropertyListDate],
[tblRegistrations].[FirstName] + ' ' + [tblRegistrations].[LastName] AS [NAME],
MAX([tblTravelKitLogs].[LogDate]) AS travelKitAddDate,
COUNT([tblTravelKitLogs].[TravelKitLogID]) AS ViewedCount
FROM
(
([tblTravelKitLogs] LEFT JOIN [tblProperties]
ON [tblTravelKitLogs].[PropertyID] = [tblProperties].[PropertyID])
LEFT JOIN [tblVOPackageDetails] ON
[tblProperties].[PackageDetailD] = [tblVOPackageDetails].[PackageDetailD]
)
LEFT JOIN [tblRegistrations] ON [tblRegistrations].[RegistrationID] = [tblVOPackageDetails].[RegistrationID]
GROUP BY
[tblProperties].[PropertyID],
[tblProperties].[PropertyName],
[tblProperties].[Region],
[tblProperties].[PropertyListDate],
[tblRegistrations].[FirstName] + ' ' + [tblRegistrations].[LastName]
GO
Does this make any sense.
Please let me know your comments now.
|
|

February 6th, 2006, 01:24 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I dont have much knowledge about C# but i think the problem is in this line:
dSetPropertyList.Tables[0].DefaultView.Sort = Session["sortExpProperty"] + " " + Session["sortExpPropertyOrder"];
'Rewrite this line as follow:
dSetPropertyList.Tables[0].DefaultView.Sort = """ + (String)Session["sortExpProperty"] + " " + (String)Session["sortExpPropertyOrder"] + """;
I hope your problem will be sorted out... Let me know what happens after you execute it..
All the best
Gaurav
|
|

February 6th, 2006, 02:09 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
No..
It is sill not working..
And I believe there is nothing to be done with the quotes.
All my thoughts goes up for searching for any possiblity by which I can assign a datatype to the dataview column..
Can I do this...If so how?
I think this could solve my problem.... Anyone there to comment on this.
Gourav, Thanks for your tries.
|
|

February 6th, 2006, 02:33 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ghari,
In VB.NET, Sort expression needs to be enclosed within the quotes.
Are you sure that in C#.NET you dont need to use quotes.
|
|

February 6th, 2006, 02:46 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The sort is woking fine...
The only problem is with Numeric data types..
It is been treated as normal string.
The problem could be with .NET dataview, so the language should not do any harm..
And I believe the .Net languages is just used to present the .Net framework namespaces and classes to the application.
May be there exists much better method to deal with our current problem.
And Im now wordering where to knock to open the lid.
|
|

February 6th, 2006, 02:54 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
In VB.NET, the syntax for sorting is :
Dataview.Sort = "Sort-Order Desc/Asc"
That's why I asked you to enclose it in quotes. Anyways, the solution could be something
else. When you come to know what is wrong in it, tell me.
I hope someone will help us.
|
|
 |