Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1076003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:21:04+00:00 2026-05-16T21:21:04+00:00

I have a data view web part on a page which is displaying a

  • 0

I have a data view web part on a page which is displaying a table of data.

I want to allow users to choose which column to sort by. I think the only way to do this is go into the data view properties, and enable the toolbar with sorting. This works and allows the user to select a column to sort using a dropdown list of columns. The default is ‘none’, and when the page first loads, there is no sorting applied (rows are shown by their ID, which is pretty much random).

I want the default sort to be a particular column – i.e. when the page is first opened, I want the data to be sorted by a ‘Surname’ column. I can’t figure out how to achieve this using the toolbar sort.

I have tried specifying an ORDER BY SURNAME in the SQL statement which gets the data – however this ends up overriding the toolbar sort, so sorting is always by surname, regardless of the toolbar sort selection.

There is another ‘sorting’ option in the data view properties which allows you to specify a sort, however again this overrides everything and renders the toolbar sorting option useless (selectiong something else has no effect).

I’m thinking surely there must be a solution to this simple problem?

The generated code for the sorting toolbar is below. I have tried making the surname the selected item in the dropdown box by changing to – this makes the surname column selected in the dropdown by default but the sorting isn’t actually applied.

Any ideas?

<table cellSpacing="0" cellPadding="2" border="0" class="ms-toolbar" style="margin-left: 3px; margin-right: 5px;">
        <tr>
            <td id="dvt_tb_sort" nowrap=""><table><tr><td nowrap="" class="ms-toolbar"><nobr>Sort by: <select>
                <xsl:variable name="clvar1_dvt_sortfield">&apos; + this.options[this.selectedIndex].value + &apos;</xsl:variable>
                <xsl:variable name="clvar2_dvt_sortfield">&apos; + this.options[this.selectedIndex].fieldtype + &apos;</xsl:variable>
                <xsl:variable name="clvar3_dvt_sortfield">&apos; + this.options[this.selectedIndex].title + &apos;</xsl:variable>
                <xsl:variable name="clvar4_dvt_sortfield">&apos; + this.options[this.selectedIndex].sorttype + &apos;</xsl:variable>
                <xsl:attribute name="OnChange">javascript:<xsl:value-of select="ddwrt:GenFireServerEvent(concat('NotUTF8;dvt_sortfield={', $clvar1_dvt_sortfield, '};dvt_sortdir={', $dvt_sortdir, '};dvt_sorttype={', $clvar4_dvt_sortfield, '}'))" /></xsl:attribute>
                <option value="">None</option>
                <option value="Location">
                <xsl:if test="$dvt_sortfield='Location'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Location</option>
                <option value="Email">
                <xsl:if test="$dvt_sortfield='Email'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Email</option>
                <option value="Mobile">
                <xsl:if test="$dvt_sortfield='Mobile'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Mobile</option>
                <option value="Position">
                <xsl:if test="$dvt_sortfield='Position'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Position</option>
                <option value="Telephone">
                <xsl:if test="$dvt_sortfield='Telephone' and not($dvt_sorttype='number')">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Telephone</option>
                <option value="Telephone" sorttype="number">
                <xsl:if test="$dvt_sortfield='Telephone' and $dvt_sorttype='number'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Telephone(Number)</option>
                <option value="Forename">
                <xsl:if test="$dvt_sortfield='Forename' or $dvt_sortfield=''">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Forename</option>
                <option value="Surname">
                <xsl:if test="$dvt_sortfield='Surname'">
                    <xsl:attribute name="selected">yes</xsl:attribute>
                </xsl:if>
                Surname</option>
                </select><a>
                <xsl:attribute name="href">
                    <xsl:choose>
                        <xsl:when test="$dvt_sortdir='descending'">javascript:<xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_sortfield={', $dvt_sortfield, '};dvt_sortdir={ascending}'))" /></xsl:when>
                        <xsl:otherwise>javascript:<xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_sortfield={', $dvt_sortfield, '};dvt_sortdir={descending}'))" /></xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
                <xsl:if test="$dvt_sortfield" ddwrt:cf_ignore="1"><img border="0">
                    <xsl:attribute name="src">
                        <xsl:choose>
                            <xsl:when test="$dvt_sortdir='descending'"><xsl:value-of select="ddwrt:FieldSortImageUrl('Asc')" /></xsl:when>
                            <xsl:otherwise><xsl:value-of select="ddwrt:FieldSortImageUrl('Desc')" /></xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    <xsl:attribute name="alt">
                        <xsl:choose>
                            <xsl:when test="$dvt_sortdir='descending'">Descending</xsl:when>
                            <xsl:otherwise>Ascending</xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    </img></xsl:if>
                </a></nobr></td></tr></table></td><td width="99%"></td>
        </tr>
    </table>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:21:05+00:00Added an answer on May 16, 2026 at 9:21 pm

    James,
    Search for the parameter binding labeled dvt_sortfield, then manually write in: Default=”FIELDNAME” line.
    This should do the trick.

    ParameterBinding Name=”dvt_sortfield” Default=”ID” Location=”Postback;Connection”

    If you need to change the default sort there is also a sort parameter called dvt_sortdir and you can set it again in the ParameterBinding tag.

    Dan

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.