Groups | Blog | Home
all groups > asp.net datagrid control > november 2003 >

asp.net datagrid control : Dynamically Adding Bound Columns Won't Sort


Mark
11/24/2003 2:02:47 PM
All-

I'm basically creating a user control which contains a datagrid that will be
used throughout our application by all pages.
My user control contains a datagrid control and I expose methods to add a
bound column to the grid.
So when they call this function and pass in the field name and title, I
dynamically add this new bound column to the
grid. It works when loaded for the first time and the paging works fine
also.
The only problem is that the Sort event doesn't fire. The bound columns are
being recreated when the page reloads,
so the grid object has them. I don't get it.


Any help would be great. Thanks

Mark
11/24/2003 5:05:10 PM
FYI:

When I binded the data back to the grid on load, the event fired. Doesn't
make sense though, because when you add static columns
to the grid in Html, you don't have to do that. What this means is that if
you create the columns dynamically in code, you have to rebind the grid in
order to get the sort event, then figure out how to sort your data, and then
rebind once again. Two binds in one postback.

Either I'm missing something, or this is bad design on MS's part.



[quoted text, click to view]

Jos
11/26/2003 1:15:02 PM
[quoted text, click to view]

This is correct. In order to get postback from controls that are created
dynamically, you need to recreate them at postback.
Then you can handle the postback event and rebuild your page once again.

I wouldn't say it's bad design, because it's not easy to handle events from
controls that don't exist anymore.

--

Jos

AddThis Social Bookmark Button