•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 402,021 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,364 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1562 | Replies: 6
![]() |
•
•
Join Date: May 2007
Posts: 10
Reputation:
Rep Power: 2
Solved Threads: 0
i have a dataview contains a column age (datatype as string)....with the data like "35/5" (i.e 35 years and 5 months) ,"9/6","101/4","23/3".....
when i am trying to sort the gridview by age asc..it diplays the result as 101/4,"23/3","35/5","9/6"
it is sort with the first char of each data...but i need the result as "9/6","23/3","35/5",101/4 like this..pls give some guide lines...
when i am trying to sort the gridview by age asc..it diplays the result as 101/4,"23/3","35/5","9/6"
it is sort with the first char of each data...but i need the result as "9/6","23/3","35/5",101/4 like this..pls give some guide lines...
•
•
Join Date: May 2007
Posts: 18
Reputation:
Rep Power: 2
Solved Threads: 1
it seems better to sort data before to send it to GridView. Can you give a code sample where you are reading data form some source and putting to GridView (all the steps from SQL (XML, etc) to GridView) ?
When you are sorting data in GridView, then sorted is only current page, but not all scope of data.
When you are sorting data in GridView, then sorted is only current page, but not all scope of data.
•
•
Join Date: May 2007
Posts: 10
Reputation:
Rep Power: 2
Solved Threads: 0
Dim dv As Data.DataView = MakeData()
dv.Sort = "Age Asc"
GridView1.DataSource = dv
GridView1.DataBind()
PrivateFunction MakeData() As Data.DataView
Dim dv As New Data.DataView
Dim dt As New System.Data.DataTable
Dim dc1 As New Data.DataColumn("Name", GetType(String))
Dim dc2 As New Data.DataColumn("Id", GetType(Integer))
Dim dc3 As New Data.DataColumn("Desc", GetType(String))
Dim dc4 As New Data.DataColumn("Con", GetType(String))
Dim dc5 As New Data.DataColumn("Age", GetType(String))
Dim strSpace As String = vbTab & vbTab & vbTab & vbTab
dt.Columns.Add(dc1)
dt.Columns.Add(dc2)
dt.Columns.Add(dc3)
dt.Columns.Add(dc4)
dt.Columns.Add(dc5)
Dim dr As Data.DataRow
dr = dt.NewRow
dr(dc1) = "Vimal"
dr(dc2) = 1
dr(dc3) = "Vincent"
dr(dc4) = dr(dc1) & strSpace & dr(dc3)
dr(dc5) = "56/5"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(dc1) = "Srini"
dr(dc2) = 2
dr(dc3) = "Ramasamy"
dr(dc4) = dr(dc1) & strSpace & dr(dc3)
dr(dc5) = "12/7"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(dc1) = "Amar"
dr(dc2) = 3
dr(dc3) = "Sudarson"
dr(dc4) = dr(dc1) & strSpace & dr(dc3)
dr(dc5) = "101/4"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(dc1) = "Rajan"
dr(dc2) = 4
dr(dc3) = "Esakki"
dr(dc4) = dr(dc1) & strSpace & dr(dc3)
dr(dc5) = "9/5"
dt.Rows.Add(dr)
dv.Table = dt
Return dv
End Function
dv.Sort = "Age Asc"
GridView1.DataSource = dv
GridView1.DataBind()
PrivateFunction MakeData() As Data.DataView
Dim dv As New Data.DataView
Dim dt As New System.Data.DataTable
Dim dc1 As New Data.DataColumn("Name", GetType(String))
Dim dc2 As New Data.DataColumn("Id", GetType(Integer))
Dim dc3 As New Data.DataColumn("Desc", GetType(String))
Dim dc4 As New Data.DataColumn("Con", GetType(String))
Dim dc5 As New Data.DataColumn("Age", GetType(String))
Dim strSpace As String = vbTab & vbTab & vbTab & vbTab
dt.Columns.Add(dc1)
dt.Columns.Add(dc2)
dt.Columns.Add(dc3)
dt.Columns.Add(dc4)
dt.Columns.Add(dc5)
Dim dr As Data.DataRow
dr = dt.NewRow
dr(dc1) = "Vimal"
dr(dc2) = 1
dr(dc3) = "Vincent"
dr(dc4) = dr(dc1) & strSpace & dr(dc3)
dr(dc5) = "56/5"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(dc1) = "Srini"
dr(dc2) = 2
dr(dc3) = "Ramasamy"
dr(dc4) = dr(dc1) & strSpace & dr(dc3)
dr(dc5) = "12/7"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(dc1) = "Amar"
dr(dc2) = 3
dr(dc3) = "Sudarson"
dr(dc4) = dr(dc1) & strSpace & dr(dc3)
dr(dc5) = "101/4"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(dc1) = "Rajan"
dr(dc2) = 4
dr(dc3) = "Esakki"
dr(dc4) = dr(dc1) & strSpace & dr(dc3)
dr(dc5) = "9/5"
dt.Rows.Add(dr)
dv.Table = dt
Return dv
End Function
•
•
Join Date: May 2007
Posts: 18
Reputation:
Rep Power: 2
Solved Threads: 1
Then the best way is to sort data in DB, in SQL-request. I do so in MS SQL, and I think there is such a possibility in Oracle too.
If you do not have access to DB, then the solution might be to create an ArrayList of items (you create some class, create an instance for each DB row, fill properties with data, and sort array list).
ArrayList is easily sorted (I have an example in C#)
arrList.Sort(new SortItems());
class SortItems : IComparer
{
public SortItems()
{
}
// Implemnentation of the IComparer:Compare
// method for comparing two objects.
public int Compare(object x, object y)
{
YourItem xItem = (YourItem)x;
YourItem yItem = (YourItem)y;
// here you compare ages and return 1 if x's age is larger than y's,
// 0 if they are equal
// and -1 if y's age is larger than x's
return 0;
}
}
And then you fill your items from ArrayList
If you do not have access to DB, then the solution might be to create an ArrayList of items (you create some class, create an instance for each DB row, fill properties with data, and sort array list).
ArrayList is easily sorted (I have an example in C#)
arrList.Sort(new SortItems());
class SortItems : IComparer
{
public SortItems()
{
}
// Implemnentation of the IComparer:Compare
// method for comparing two objects.
public int Compare(object x, object y)
{
YourItem xItem = (YourItem)x;
YourItem yItem = (YourItem)y;
// here you compare ages and return 1 if x's age is larger than y's,
// 0 if they are equal
// and -1 if y's age is larger than x's
return 0;
}
}
And then you fill your items from ArrayList
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Need Urgent Help in Sorting (Shell Scripting)
- sorting and functions/structures (C)
- sorting 2d arrays (C)
Other Threads in the ASP.NET Forum
- Previous Thread: DropDown List selectedvalue
- Next Thread: Any one knows good webhosting on ASP.NET


Linear Mode