开发者

How to arrange the items of gridview?

开发者 https://www.devze.com 2022-12-26 13:55 出处:网络
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开

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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号