Newbie question on databinding

O

ORi

Hi,

I'm a .Net developer facing his first aspnet development. I'm having
some problems understanding how controls and datasources work, this is
the situation I have:

An aspnet page with some textboxes in it and a datagrid, each textbox
maps a field from a table in a typed dataset and the datagrid maps the
whole datatable (it has a template column with checkboxes in it added
dynamically).
The page loads at first data from the database and databinds the
controls to the dataset, now the textboxes are filled with the data
from the first row and the datagrid has all the records. What I'd like
to understand, is what should I do when there's a Postback in the
page: Then, the datasource is null again. Should I load it from the
database on the page_load event for each time I load the page ? maybe
should I store it in Session the first time I load it ? Which is the
correct way to proceed ? I thought aspnet would handle all this
situation for me and keep the datasource up to date between postbacks
and updating it with the content from my controls (like winforms
applications do) is there any way I don't know to achieve this ?

Also, another problem I face, is that after reloading the datasource,
I call again a Page.DataBind() to update the controls. However, after
calling databind the datagrid looses all it's state (which I store in
his viewstate because I've inherited the datagrid in my own class) as
well as the state of it's checkboxes from the template column. As I
see, if I use this approach I loose the utility of the control's
viewstate ! so should I call databind on each reload ? I have tried to
call databind on all controls except datagrid but then If I reload
data from the database I may have different data If some other person
has updated the table in between my calls (as datagrid keeps his data
from the page's viewstate)

I hope you understand everything ! I'm looking for a way to deal with
this kind of situations, how is databinding supposed to be implemented
? Am I doing right or there's a better way to do it ?

thx in advance, any advice will be appreciated !
ori
 
E

Eliyahu Goldin

Yes, you should reload and rebind your data on every postback. That is the
way how web application works, very different from Windows ones. You still
can use session variables for storing a few frequently used parameters.

As far as another problem is concerned, if I got it correctly, you should
make a procedure that will setup your grid according to the dataset content
and call it on every postback.

Eliyahu
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top