I have a gridview in my aspx page.On the page_load i will be adding the boundfields to it.Now,based upon the value selected from a dropdown I need to change the order in which the columns arde displayed.Is it possible.
On the page_load i will be adding the boundfields to it.
Don't. If you want PostBacks to work properly, they need to be added in the Init Phase. Use Page_Init if you can.
Now,based upon the value selected from a dropdown I need to change the order in which the columns arde displayed.Is it possible.
GridView will build rows during DataBind. The Cells will be ordered in accordance with the Columns. So if you order Columns right, and then DataBind, that should work.
One snag, though. As said, to make PostBack work properly, you need to add the Columns in the Init Phase. The order in that will have to match that of the last request. And you will not have the value of the DropDownList available at that time. Also, in
the Init Phase ViewState may not be available for use yet. Not sure how I would go about this. It's not easy.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
dotnet16
Member
155 Points
113 Posts
Reorder gridview columns
Jun 17, 2011 07:24 AM|LINK
Hi
I have a gridview in my aspx page.On the page_load i will be adding the boundfields to it.Now,based upon the value selected from a dropdown I need to change the order in which the columns arde displayed.Is it possible.
Please let me know your suggestions.
hassanmehmoo...
Star
8970 Points
1590 Posts
Re: Reorder gridview columns
Jun 17, 2011 07:28 AM|LINK
When you will choose from dropdownlist and will postback to make changes, you will need to do the same what u just did above.
Means adding those columns again (but this time in the order mentioned in your dropdownlists)
--
Hope this helps..
Mark as Answer, if it answers you..
--
bhupalb
Participant
777 Points
160 Posts
Re: Reorder gridview columns
Jun 17, 2011 07:34 AM|LINK
hi it is possible with the follwoing method of columns of table
change the order
Table.Columns["Column Name"].SetOrdinal(NewIndex);
B Bhupal
dotnet16
Member
155 Points
113 Posts
Re: Reorder gridview columns
Jun 17, 2011 08:11 AM|LINK
Hi Bhupal,
This is for DataTable right?Does such a property exist for GridView?
bhupalb
Participant
777 Points
160 Posts
Re: Reorder gridview columns
Jun 17, 2011 08:34 AM|LINK
ya it is DataTable only while assigning the datatable to grid view apply that function and assign to the grid view
ok
superguppie
All-Star
48225 Points
8679 Posts
Re: Reorder gridview columns
Jun 17, 2011 09:20 AM|LINK
Don't. If you want PostBacks to work properly, they need to be added in the Init Phase. Use Page_Init if you can.
GridView will build rows during DataBind. The Cells will be ordered in accordance with the Columns. So if you order Columns right, and then DataBind, that should work.
One snag, though. As said, to make PostBack work properly, you need to add the Columns in the Init Phase. The order in that will have to match that of the last request. And you will not have the value of the DropDownList available at that time. Also, in the Init Phase ViewState may not be available for use yet. Not sure how I would go about this. It's not easy.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.