Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 9th, 2014, 03:43 AM
Registered User
 
Join Date: May 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to: Click header to sort records desc or asc

I am having problem to make the records in the table sort in desc or asc order, when user click on the header.

One click on one of the header title such as (date) desc then another click back asc/ or another way round.

The records retrieve from SQL data via array method.
When the record appear in the page, the user can click any of the title to perform sorting base on the title.


Below are my XSLT.

How to sort by using the header No., DN and MM?
Hope someone can advice me on this please, thank you.
***********************************
<xsl:template match="/Array">


<table id="Table1" cellspacing="0" cellpadding="2" style="width:500px;">
<tr>
<th width="50" align="left">No.</th>
<th align="left">DN</th>
<th align="center">MM</th>
<center>
<input type="button" value="Edit" onClick="OpenMEditPanel(this); "></input>
</center>
</th>
<th align="center">
<center>
<input type="button" value="Select All" onClick="SelectAll(); "></input>
</center>
</th>
<th align="center">
<center>
<input type="button" value="Delete" onclick="DeleteMChecked();"></input>
</center>
</th>
</tr>


<xsl:for-each select ="NameMaster" >
<xsl:variable name ="count" >
<xsl:value-of select="position()"/>
</xsl:variable>
<xsl:variable name="TdN">
<xsl:value-of select ="DN"/>
</xsl:variable>
<xsl:variable name ="Tmm" >
<xsl:value-of select ="Mm"/>
</xsl:variable>


<tr>
<xsl:if test="position() mod 2 = 0">
<xsl:attribute name="bgcolor">#F4F4F4</xsl:attribute>
</xsl:if>
<td align="left" valign="top" id="No">
<xsl:value-of select ="position()" ></xsl:value-of>
</td>
<td align="left" valign="top" id="TdN">
<xsl:value-of select ="DN" ></xsl:value-of>
</td>
<td align="left" valign="top" id="Tmm">
<xsl:value-of select ="Mm" ></xsl:value-of>
</td>

<td></td>
<td align="center" valign="top" id="Select">
<input type="checkbox" name="chkBoxE" onclick="collectMChecked('{TdN}');" value="{DN}"></input>
</td>

</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

****************************
 
Old May 12th, 2014, 05:40 PM
Registered User
 
Join Date: May 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default click header to sort records asc

SqlConnection myconn = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"];
string strcon = "SELECT * FROM table order by datecreated asc";
.........
.........
.........

try the code if it will be useful
 
Old May 13th, 2014, 05:14 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Firstly, in answer to the OP:

There isn't anything in XSLT specifically that allows you to do what you are asking. You need to generate something from the XSLT that would either refresh the page (if we are talking web site), either in JavaScript, or just as a full href link.

There is a version of Saxon XSLT CE (Client Edition) which does add the idea of 'events' to XSLT, but I don't know how that works or if that helps, as you are probably running your XSLT on the server in the first place: http://www.saxonica.com/ce/index.xml

Secondly, Benjoo: I don't think some C# code telling him how to connect to a database is going to be helpful for an XSLT issue.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use IN statement with asc/desc in ORACLE/SQL queries? arbab SQL Language 1 September 20th, 2010 08:46 AM
How to use IN statement with asc/desc in ORACLE queries? arbab Oracle 1 September 20th, 2010 03:38 AM
User selection to sort records in a Crystal Report MisterN Crystal Reports 1 January 24th, 2007 01:03 PM
Sort Records Based on Totals mvollmer Classic ASP Databases 1 July 11th, 2004 11:22 AM
How to put Desc/Asc triangle symbol on List View? hplim18 VB How-To 1 May 10th, 2004 12:17 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.