Dynamically Adding Bound Columns Won't Sort

M

Mark

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
 
M

Mark

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.
 
J

Jos

Mark said:
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top