Morning,

I have a Standard gridview within a update panel, in the last column I have buttons for up and down which run the below JS to move the entire rows up and down... it all works GREAT, until I come to save it.

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);
            }
        }
    }
}

even though I get the Behind to read the gridview row by row, cell by cell it only loads what the original table was....infuriating.

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();

(Footer text was a cheap way to preserve the original column headers when reading)

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>

HOW CAN I GET THIS TO SAVE... Please....:(

Related posts

Recent Viewed