Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ASP.NET asp:Table how do I swap rows in server side code

Posted on 2010-08-18
3
627 Views
Last Modified: 2012-05-10
Asp code
<asp:Table id='tabel1" runat="server">
<asp:TableRow id="trow1">
<asp:TableCell>
Row1
</asp:TableCell>
</asp:TableRow>
<asp:TableRow id="trow2">
<asp:TableCell>
Row2
</asp:TableCell>
</asp:TableRow>

</asp:Table>

I want to swap row1 with row2.
0
Comment
Question by:TheAnvilGroup
3 Comments
 
LVL 18

Expert Comment

by:Anil Golamari
ID: 33466902
You can swap table rows on the client-side by swapping the cell contents of the
current rows and the row to swap. The following method takes three parameters:
the current table row element, a Boolean to indicate whether the row should move
up, and a Boolean to indicate whether the first row should be ignored.

function SwapRows(rowElem, dirUp, ignoreFirstRow) {
var rowElemToSwap = (dirUp) ? rowElem.previousSibling :
rowElem.nextSibling;
// Firefox returns a blank text node for the sibling
while (rowElemToSwap && rowElemToSwap.nodeType != 1) {
rowElemToSwap = (dirUp) ? rowElemToSwap.previousSibling :
rowElemToSwap.nextSibling;
}
if (rowElemToSwap && !(ignoreFirstRow && rowElemToSwap.rowIndex ==
0)) {
var rowCells = rowElem.cells;
var colInner;
for (var i = 0, loopCnt = rowCells.length; i < loopCnt; i++) {
colInner = rowCells[i].innerHTML;
rowCells[i].innerHTML = rowElemToSwap.cells[i].innerHTML;
rowElemToSwap.cells[i].innerHTML = colInner;
}
}
}
For reference: http://www.karamasoft.com/whitepapers/JavaScript-Tips-Part1.pdf
Can you try this.

Good Luck.
0
 
LVL 2

Accepted Solution

by:
tn-vadimc earned 125 total points
ID: 33467114
           TableRow tmpRow = new TableRow();
            tmpRow = tabel1.Rows[0];
            tabel1.Rows.Remove(tabel1.Rows[0]);
            tabel1.Rows.Add(tmpRow);

0
 
LVL 1

Author Closing Comment

by:TheAnvilGroup
ID: 33473078
Although javascript would work and is a good solution, I was asking for server side code.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question