Of DataGrids, DataBinding and Server-side Events

G

Good Enchiladas

I have a class inheriting from CollectionBase that is displayed in a
datagrid. When the user clicks on a button, the current record in the data
grid is deleted.

Unfortunately, I have to populate my CollectionBase class first in the
Page_Load event then databind it to the datagrid. Then the button click
event uses the populated datagrid to determine the currently selected row
and then performs the delete. Then in the Page_PreRender event I have to
again populate my CollectionBase class and databind it a second time to the
datagrid in order to get the deleted record to disappear.

If I don't load the grid in Page_Load, the button click doesn't fire. If I
don't load in Page_PreRender (or some event after the button click event)
then the record won't disappear from the datagrid.

This seems really wasteful. I have to be doing something wrong. Can someone
tell me a better way to get this working?
 
M

Martin Dechev

Hi, Good Enchiladas,

You can reset the DataSource and call DataBind() right after you delete the
record in the button click handler.

Greetings
Martin
 
G

Good Enchiladas

True, and that would result in a less funky code by not using PreRender. But
I am still doing a double load, which seems inefficient to me.

Thank you.
 
M

Martin Dechev

Can you post a small example that shows what you're doing and how you are
doing it. It will be easier to point out the possible optimizations.

Greetings
Martin
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top