Sort Dataset without binding to datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aeric
    New Member
    • Mar 2009
    • 1

    Sort Dataset without binding to datagrid

    I have read the following topic:
    sorting dataset
    and I am facing the same issue.

    I am designing a report. I have fill a dataset with the results from a query. From the results, I used to set the value from the items into an array and display on the aspx page in a table form. The reason why I don't use Datagrid or Gridview is because the table has to be design where the column headers has 2 or more rows and some columns need to be merged using colspan and rowspan. The HTML table also can provide me with the hover function for Alternate Text which is dynamic change for each column and rows. ASP.NET controls are lack in these features as I know. I also have linkbutton inside a cell with another static label.

    My problem here is that I want to sort the rows of records from the table. My idea is to add linkbutton for the column header title so when click, the rows will be sorted as Ascending or Descending.

    I have at least 7 columns to be sorted. If I have to modify the stored procedure then I need to pass in 7 parameters together with the Sort Order (Asc/Desc) for each parameter which will make the stored procedure become long and complicated. I have tried DefaultView property but the dataset is not sorted.

    Code:
        Protected Sub lnkSortRegion_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSortRegion.Click
            SetParams()
            GetDataset()
            If lnkSortRegion.Text = "A-Z" Then
                dataset1.Tables(0).DefaultView.Sort = "Region"
                lnkSortRegion.Text = "Z-A"
            Else
                dataset1.Tables(0).DefaultView.Sort = "Region Desc"
                lnkSortRegion.Text = "A-Z"
            End If
            PopulateDataToArray()
        End Sub
    Expert there please help me. Thanks.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    The Table.DefaultVi ew property returns a DataView associated with the table.

    It can be used for sorting, filtering, searching, editing, and navigation. When you do sorting, filtering, or editing on the DataView, it has no effect on the DataTable it is associated with. This lets you create multiple views of the DataTable without modifying the source.

    This means that when you do your sorting and call your PopulateDataToA rray() method, you need to use the DataView instead of the DataTable in your DataSet.

    I'd recommend modifying your PopulateDataToA rray() method so that it accepts a parameter: the data source that should be displayed.

    -Frinny

    Comment

    Working...