If I have a table in .aspx
<table id="table" >
<tr id="first" runat="server"> blablabla>
<td></td>
</tr>
<tr id="second" runat="server">
<td></td>
</tr>
</table>
How can I change order from second to firs开发者_开发技巧t in the code behind?
I tried to wrap tr with placeholders and hide/display them accordingly, but it doesn't allow me to do that as I get duplicate IDs inside these rows. And I can't use javascript for that..
As you have not set either tr
or table
as server side code (by using a runat="server"
attribute), they are not visible to the code behind and it cannot change the ordering.
In aspx:
<table id="table" runat="server">
<tr id="first" runat="server">
<td>blablabla</td>
</tr>
<tr id="second" runat="server">
<td> </td>
</tr>
</table>
In code behind:
var row = table.Rows[0]; // get reference to first row
table.Rows.Remove(row); // remove it
table.Rows.Add(row); // Add again, at the end (default)
Since this is static markup rather than a server side control (none of the tags are set to runat="server"
), the server side C# code can't modify them.
精彩评论