ASP.NET 2.0 Question:
Download Questions PDF

How do we Sort the data from a Dataset?

Answer:

Sorting is similar to filtering, in that you specify a sort expression. A typical sort expression is simply the name of the column to sort by. For example, to sort by the OrderDate column, you specify the sort expression OrderDate. However, you can sort by the value of any expression, including calculated values. If you call a table's Select method, you pass the sort expression as a parameter. If you are using data views, you specify the sort expression as the value of the view's "Sort" property.EX:' Visual BasicDim filterExp As String = "Status = 'Active'"Dim sortExp As String = "City"Dim drarray() As DataRowDim i As Integerdrarray = dataSet1.Customers.Select(filterExp, sortExp, DataViewRowState.CurrentRows)For i = 0 To (drarray.Length - 1) listBox1.Items.Add( drarray(i)("City").ToString )Next// C#string filterExp = "Status = 'Active'";string sortExp = "City";DataRow[] drarray;drarray = dataSet1.Customers.Select(filterExp, sortExp, DataViewRowState.CurrentRows);for (int i=0; i < drarray.Length; i++){ listBox1.Items.Add(drarray[i]["City"].ToString());}

Download ASP.NET 2.0 Interview Questions And Answers PDF

Previous QuestionNext Question
How do we get only edited/deleted/inserted records from a Dataset?Diff between Web User Control and Web Custom Control?