[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2010-08-18
3
Medium Priority
?
641 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
[X]
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
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 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 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