如何在按钮单击时对gridview中的行进行随机播放或重新排序

时间:2011-09-06 12:57:30

标签: javascript asp.net gridview radgrid

我有radgrid,我从后面的代码绑定数据,我的网格控件旁边有两个按钮,一个移动按钮和移动按钮。在选择网格上的特定行并单击“上移”按钮时,我必须将该行向上移动。我如何交换行?

我正在尝试实现以下代码,但由于某些原因,我的MoveRowUp()和MoveRowDown()事件未在javascript中触发。

<head runat="server">  
    <title>Untitled Page</title> 
    <script type="text/javascript">  
                var SelectedRow;  
                function RowSelected(rowObject)  
                {  
                    SelectedRow = rowObject;  
                }  

                function MoveRowUp()  
                {  
                    if (SelectedRow && SelectedRow.Control.sectionRowIndex > 0)  
                    {  
                        SerializeReorderChanges(SelectedRow.Control.sectionRowIndex, SelectedRow.Control.sectionRowIndex - 1);  
                        SelectedRow.Control.swapNode(SelectedRow.Control.parentNode.rows[SelectedRow.Control.sectionRowIndex - 1]);  
                    }  
                }  

                function MoveRowDown()  
                {  
                    if (SelectedRow && SelectedRow.Control.sectionRowIndex < SelectedRow.Control.parentNode.rows.length - 1)  
                    {  
                        SerializeReorderChanges(SelectedRow.Control.sectionRowIndex, SelectedRow.Control.sectionRowIndex + 1);  
                        SelectedRow.Control.parentNode.rows[SelectedRow.Control.sectionRowIndex + 1].swapNode(SelectedRow.Control);  
                    }  
                }  

                function SerializeReorderChanges(index1, index2)  
                {  
                    var reorderInput = document.getElementById("ReorderChanges");  
                    if (reorderInput)  
                    {  
                        reorderInput.value += index1 + "," + index2 + ";";  
                    }  
                }  

                if(window.netscape)  
                {  
                    Node.prototype.swapNode = function(node)   
                    {  
                        var nextSibling = this.nextSibling;  
                        var parentNode = this.parentNode;  
                        node.parentNode.replaceChild(this, node);  
                        parentNode.insertBefore(node, nextSibling);  
                    }  
                }  
    </script> 
</head> 
<body> 
    <form id="form1" runat="server">  
        <div> 
            <input type="hidden" name="ReorderChanges" id="ReorderChanges">  
            <input type="button" value="Move selected row up" onclick="MoveRowUp()">  
            <br /> 
            <input type="button" value="Move selected row down" onclick="MoveRowDown()">  
            <radG:RadGrid ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" runat="server">  
                <ClientSettings> 
                    <Selecting AllowRowSelect="True"></Selecting> 
                    <ClientEvents OnRowSelected="RowSelected"></ClientEvents> 
                </ClientSettings> 
            </radG:RadGrid> 
            <input type="button" value="Apply changes server side" onclick="__doPostBack('<%= RadGrid1.ClientID %>','ReorderedRows:' + document.getElementById('ReorderChanges').value);">  
        </div> 
    </form> 
</body> 
</html> 

0 个答案:

没有答案