This is a migrated thread and some comments may be shown as answers.

persist the reordered grid info

3 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luís
Top achievements
Rank 1
Luís asked on 14 Dec 2011, 02:28 AM
Hi, I would like to persist the grid row order after the user reorder it.
I'm almost there, but i cant get the "updated" values from the grid. Whenever I access the e.DestinationGrid.Items or the grid.Items on the RowDrop event, the grid isnt updated yet, so i'm stuck with the old values.

ASPX:
<div>
    <telerik:RadGrid ID="gridSubjects" runat="server" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" Skin="Telerik" OnDeleteCommand="gridSubjects_DeleteCommand"
        OnNeedDataSource="gridSubjects_NeedDataSource" OnInsertCommand="gridSubjects_InsertCommand"
        OnUpdateCommand="gridSubjects_UpdateCommand"
        onrowdrop="gridSubjects_RowDrop">
        <ClientSettings AllowRowsDragDrop="true" EnablePostBackOnRowClick="True">
            <Selecting AllowRowSelect="True" EnableDragToSelectRows="false" />
        </ClientSettings>
        <MasterTableView DataKeyNames="SubjectID,Sequence" InsertItemPageIndexAction="ShowItemOnCurrentPage"
            AutoGenerateColumns="false" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Adicionar"
            CommandItemSettings-RefreshText="Atualizar">
            <CommandItemSettings AddNewRecordText="Adicionar" RefreshText="Atualizar" ExportToPdfText="Export to PDF">
            </CommandItemSettings>
            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
            </RowIndicatorColumn>
            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridDragDropColumn Visible="true" />
                <telerik:GridTemplateColumn DataField="SubjectID" HeaderText="ID" UniqueName="SubjectID"
                    Visible="false" ReadOnly="true">
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="Name" HeaderText="Nome" UniqueName="Name" />
                <telerik:GridBoundColumn DataField="Description" HeaderText="Descrição" UniqueName="Description" />
                <telerik:GridHyperLinkColumn DataNavigateUrlFields="SubjectID" DataNavigateUrlFormatString="~/TrainingsControl/Topics.aspx?SID={0}"
                    DataTextField="TopicsCount" DataTextFormatString="Tópicos ({0})" UniqueName="TopicsCount" />
                <telerik:GridHyperLinkColumn DataNavigateUrlFields="QuizID,SubjectID" DataNavigateUrlFormatString="~/TrainingsControl/QuizzesControl/Quiz.aspx?QID={0}&SID={1}"
                    UniqueName="Quiz" DataTextField="QuestionsCount" DataTextFormatString="Questionário ({0})" />
                <telerik:GridEditCommandColumn ButtonType="ImageButton" />
                <telerik:GridButtonColumn ConfirmText="Deseja realmente deletar o módulo?" ConfirmDialogType="RadWindow"
                    ConfirmTitle="Confirmação" ButtonType="ImageButton" CommandName="Delete" ConfirmDialogHeight="100px"
                    ConfirmDialogWidth="220px" />
            </Columns>
            <EditFormSettings>
                <EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column">
                </EditColumn>
            </EditFormSettings>
        </MasterTableView>
        <StatusBarSettings LoadingText="Carregando..." ReadyText="Pronto" />
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Telerik">
        </HeaderContextMenu>
    </telerik:RadGrid>
</div>


c#
protected void gridSubjects_RowDrop(object sender, GridDragDropEventArgs e)
{
    Subject subject = new Subject();
    Dictionary<int, short> order = new Dictionary<int, short>();
    //I tried the alternative below too
    //foreach (GridDataItem item in gridSubjects.Items)
    foreach (GridDataItem item in e.DestinationGrid.Items)
    {
        int subID = Int32.Parse(item.GetDataKeyValue("SubjectID").ToString());
        short subSeq = Int16.Parse(item.GetDataKeyValue("Sequence").ToString());
        order.Add(subID, subSeq);
    }
    using (Pro10Entities db = new Pro10Entities())
    {
        subject.Reorder(db, order);
    }
}



So, can someone help?
Thanks! And sorry for the english!

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Dec 2011, 05:10 AM
Hello Luis,

Check the following demo which implements the same.
Grid / Column/Row Resize/Reorder

-Shinu.
0
Luís
Top achievements
Rank 1
answered on 16 Dec 2011, 01:05 AM
Sorry, this example doesnt implements the row reorder + persist.
:(
0
Pavlina
Telerik team
answered on 16 Dec 2011, 12:34 PM
Hello Luís,

The following online example demonstrates how you can persist OrderIndex of grid columns:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/savinggridsettingsonperuserbasis/defaultcs.aspx


Best wishes,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Luís
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Luís
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or