在JS移动行之后保存Gridview

时间:2015-09-04 07:43:58

标签: javascript c# asp.net gridview

上午,

我在更新面板中有一个标准gridview,在最后一列我有上下按钮,运行下面的JS来上下移动整行...这一切都很好,直到我来保存它

function SendUp(CurrentRow, PreviousRow) 
{
    PreviousRow.parentNode.insertBefore(CurrentRow, PreviousRow);
}
function MoveUp(obj) 
{
    var index = obj.parentElement.parentElement.rowIndex;
    var RightTable = document.getElementById("<%= grd_alter_reorder.ClientID %>");

    var i = 0;

    for (i = 2; i < RightTable.rows.length; i++) {
        if (i == index) //is selected ?
        {
            SendUp(RightTable.rows[i], RightTable.rows[i - 1]);
        }
    }
}

//function to select a row to move down
function MoveDown(obj) 
{
    var index = obj.parentElement.parentElement.rowIndex;
    var RightTable = document.getElementById("<%= grd_alter_reorder.ClientID %>");
    var i = 0;
    var RowToMove = 0;
    var PreviousRow;
    var CurrentRow;

    for (i = 1; i < RightTable.rows.length - 1; i++) {
        if (i == index) {
            RightTable.rows[i];

            RowToMove = i;

            //appends the selected row to the end of the Right Table
            RightTable.rows[i].parentNode.appendChild(RightTable.rows[i]);

            //this code moves the appended row up till it reaches
            //to one position less than its original position
            for (i = RightTable.rows.length - 1; i > RowToMove + 1; i--) {
                CurrentRow = RightTable.rows[i];
                PreviousRow = RightTable.rows[i - 1];

                SendUp(CurrentRow, PreviousRow);
            }
        }
    }
}

即使我让Behind逐行读取gridview,逐个单元格,它只加载原始表格......真气。

DataTable Gdt1 = new DataTable();
for (int i = 0; i < grd_alter_reorder.Columns.Count - 1; i++)
{
    Gdt1.Columns.Add(grd_alter_reorder.Columns[i].FooterText);
}
foreach (GridViewRow row in grd_alter_reorder.Rows)
{
    DataRow dr = Gdt1.NewRow();
    for (int j = 0; j < grd_alter_reorder.Columns.Count - 1; j++)
    {

        dr[grd_alter_reorder.Columns[j].FooterText] = row.Cells[j].Text;
    }

    Gdt1.Rows.Add(dr);
}
grd_alter_reseq.DataSource = Gdt1;
grd_alter_reseq.DataBind();

(页脚文本是一种在阅读时保留原始列标题的便宜方式)

的GridView

<asp:GridView ID="grd_alter_reorder" ShowFooter="false" AutoGenerateColumns="False" runat="server" CssClass="mGrid4" EmptyDataText="Select Run Plan To Continue" Height="75%" Width="75%">
<Columns>
    ***Bound Fields***
    <asp:TemplateField HeaderText="Operations" FooterText="Operations" HeaderStyle-width="15%">
        <ItemTemplate>
            <asp:ImageButton ID="Img_Up1" ImageUrl="images/Arrow1Up.png" AlternateText="Move Up" OnClientClick="MoveUp(this);return false;" runat="server" />
            <asp:ImageButton ID="Image_Down1" ImageUrl="images/Arrow1Down.png" AlternateText="Move Down" OnClientClick="MoveDown(this);return false;" runat="server" />
        </ItemTemplate>
    </asp:TemplateField>
</Columns>

我怎样才能得到这个......请...... :(

0 个答案:

没有答案