Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
659 views
in Technique[技术] by (71.8m points)

.net - DataBind and Postback

This is a general how does DataBind work questions...

I have a simple page with a GridView that is bound (in the aspx code) to an ObjectDataSource.

I can look in the Select() function called by the ObjectDataSource to see that it is called on the initial load and on every post back. I have some logic that happens on post backs that will affect the GridView's data, and I want to call GridView.DataBind() later on in the post back, after I've made some changes.

Is there a way to prevent the automatic rebinding that happens on each post back? Does this mean I can't use an ObjectDataSource for this control?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're correct in that the fine grained control you're looking for is not possible and requires the code behind. ASP.NET's data source objects are nothing but a pain in the a**. You'll find that as you use them you'll get situations like this cropping up again and again.

Some of the problems you'll find are:

  • Not strongly typed
  • Inflexible (as you've noted)
  • Muddy up the presentation code

I've taken to doing all data access in the code behind and haven't looked back.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...