Sorting with the ADC Data Controls

Last post 07-30-2008 8:23 AM by xxxd. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 07-29-2008 12:30 PM

    Sorting with the ADC Data Controls

    Hi,

    I've got this from another thread and wanted to ask further questions (see below), hence this new thread. Here's the code:

    And in terms of sorting, take a look at the sorting.aspx example.

    Its set up is the same as regular gridview controls. And when load datasource, you set up the sort column

       function loadData()
            {
                //Need to convert the sortoder so our WS understand
                var sortColumn = _gridView.get_sortColumn();
                var sortOrder = (_gridView.get_sortOrder() == AjaxDataControls.GridViewSortOrder.Descending) ? 'DESC' : 'ASC';

                DataService.GetData(0, 1000, sortColumn, sortOrder, onLoadSuccess);
            }

       function onSortCommand(sender, e)
            {
                _gridView.set_sortColumn(e.get_sortColumn())
                _gridView.set_sortOrder(e.get_sortOrder());
                loadProducts();
            }

     

    My first question is, how do I set which columns should be sorted on the GridView?  Do I do this in the properties of the gridview in design view?

    Secondly, could you explain why the sortColumn and sortOrder are passed to the webservice method?  What does the method need to do and return?

    Lastly, could you give me a brief overview fo how this all fits together?

    Thanks.

     

    dbrook007
  •  Advertisement

    3 MONTHS FREE & FREE SETUP on ASP.NET 3.5/2.0 Web Hosting! Windows 2008 & 2003 Servers Available, MS SQL 2008/2005, .NET 3.5 SP1, Entity Framework, LINQ, Silverlight 2.0, 30 Day Money Back Guarantee – Click Here!

     
  • 07-29-2008 12:44 PM In reply to

    • Sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 10,367
    • MVP

    Re: Sorting with the ADC Data Controls

    You define the SortField property on the Columns to set the sort. If you do not want to sort that field, then do not define this.

    The sortColumn is passed to the webservice to know, which column to sort. The sortOrder is passed to know whether the user wants to sort Ascending or Descending.

    The Webservice should then take these parameters and sort your dataTable.

    Dim dt As New DataTable
    ...
    Dim view As DataView = dt.DefaultView
    view.Sort = sortColumn & " " & sortOrder

    Something like this, should do it.

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
  • 07-29-2008 12:48 PM In reply to

    • xxxd
    • Top 10 Contributor
    • Joined on 12-18-2006
    • Wannabe Slacker
    • Points 15,798

    Re: Sorting with the ADC Data Controls

    dbrook007:

    My first question is, how do I set which columns should be sorted on the GridView?  Do I do this in the properties of the gridview in design view?

     

    set the sortField property in individual columns. For example

     <Columns>
                <AjaxData:GridViewBoundColumn HeaderText="Product" DataField="Name" SortField="Name" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" HeaderStyle-Wrap="false"/>
                <AjaxData:GridViewBoundColumn HeaderText="Category" DataField="CategoryName" SortField="CategoryName" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" HeaderStyle-Wrap="false"/>
                <AjaxData:GridViewBoundColumn HeaderText="Supplier" DataField="SupplierName" SortField="SupplierName" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" HeaderStyle-Wrap="false"/>
                <AjaxData:GridViewBoundColumn HeaderText="Quantity/Unit" DataField="QuantityPerUnit" SortField="QuantityPerUnit" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="left"/>
                <AjaxData:GridViewBoundColumn HeaderText="Unit Price" DataField="UnitPrice" SortField="UnitPrice" DataFormatString="c" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Right" HeaderStyle-Wrap="false"/>
                <AjaxData:GridViewBoundColumn HeaderText="Units In Stock" DataField="UnitsInStock" SortField="UnitsInStock" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Right" HeaderStyle-Wrap="false"/>
                <AjaxData:GridViewBoundColumn HeaderText="Units On Order" DataField="UnitsOnOrder" SortField="UnitsOnOrder" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Right" HeaderStyle-Wrap="false"/>
                <AjaxData:GridViewCheckBoxColumn HeaderText="Discontinued" DataField="Discontinued" SortField="Discontinued" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Center" HeaderStyle-Wrap="false"/>
           </Columns>

     

    dbrook007:

    Secondly, could you explain why the sortColumn and sortOrder are passed to the webservice method?  What does the method need to do and return?

     So that you can specify which column to sort and how to sort: descending or ascending

    dbrook007:

    Lastly, could you give me a brief overview fo how this all fits together?

     To respond to a sort command, do this

     

    function onSortCommand(sender, e)

    {

    _gridView.set_sortColumn(e.get_sortColumn())

    _gridView.set_sortOrder(e.get_sortOrder());

    }

  • 07-30-2008 6:02 AM In reply to

    Re: Sorting with the ADC Data Controls

    Hi,

    re:

    Sonu:

    You define the SortField property on the Columns to set the sort. If you do not want to sort that field, then do not define this.

    The sortColumn is passed to the webservice to know, which column to sort. The sortOrder is passed to know whether the user wants to sort Ascending or Descending.

    The Webservice should then take these parameters and sort your dataTable.

    Dim dt As New DataTable
    ...
    Dim view As DataView = dt.DefaultView
    view.Sort = sortColumn & " " & sortOrder

    Something like this, should do it.

     

     

    I am using template fields.  In the first column, the template field shows more than data item.  How can I sort when using template fields?

    Thanks.

     

    dbrook007
  • 07-30-2008 8:23 AM In reply to

    • xxxd
    • Top 10 Contributor
    • Joined on 12-18-2006
    • Wannabe Slacker
    • Points 15,798

    Re: Sorting with the ADC Data Controls

    I think you can still do the same as the following          

     <AjaxData:GridViewTemplateColumn HeaderText="Category" SortField="CategoryName" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" HeaderStyle-Wrap="false">
                                <ItemTemplate>
                                    <span id="spnCategory"></span>
                                    <span id="spnAnotherField"></span>
                                </ItemTemplate>
                   </AjaxData:GridViewTemplateColumn>

     

Page 1 of 1 (5 items)