Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net mvc input file 2 32
Tool Box 2 34
Any Third party toll for Integrating chat system on ASP.NET ? 2 34
When should I use a controller? 3 16
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

22 Experts available now in Live!

Get 1:1 Help Now