views:

41

answers:

1

I have a settings page in my asp.net website,in which a user can select desired items and their order to be displayed in another page.I am displaying these items(which are obtained from database) in a gridview with checkboxes,up/down arrows next to them.Once the user makes his selection/rearranges the items and clicks on the 'Save' button,I am saving the data into another database table.When this particular user logsin again I want to check the items which were already chosen by him and arrange them in the order he specified, on page load.I am able to check the checkboxes of the already chosen items but do not understand how do I arrange the items in the user specified order?

Update: Basically 'items' in my question refers to column names of a database table.so once the user selects his desired column names and their order,the data corresponding to these columns gets displayed in another page in the column sequence specified.

Please help.

Thanks.

+3  A: 

You can dynamically bind the columns in the code behind in the page load section. This article explains a method for doing that:

How to Create Columns Dynamically in a Grid View

Basically it says to loop through the data in the order selected and for each column add it to the gridview in that order, e.g.

        //Declare the bound field and allocate memory for the bound field.
        BoundField bfield = new BoundField();

        //Initalize the DataField value.
        bfield.DataField = col.ColumnName;

        //Initialize the HeaderText field value.
        bfield.HeaderText = col.ColumnName;

        //Add the newly created bound field to the GridView.
        GrdDynamic.Columns.Add(bfield);
Turnkey