Solved

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

Posted on 2010-08-18
3
622 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
Comment Utility
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
Comment Utility
           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
Comment Utility
Although javascript would work and is a good solution, I was asking for server side code.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now