Solved

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

Posted on 2010-08-18
3
626 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 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