Why is the DataBind() method necessary?

前端 未结 4 1436
逝去的感伤
逝去的感伤 2020-12-09 04:26

Simple question, I guess.

For a long time I\'ve blindly followed a (supposedly) common pattern when programmatically databinding my ASP.NET controls. Namely:

4条回答
  •  忘掉有多难
    2020-12-09 05:17

    In ASP.Net, it's often important to have certain data available and ready at certain points in the page life cycle, and not before. For example, you may need to bind to a drop down list early to allow setting the selected index on that list later. Or you might want to wait a bit to bind that large grid to reduce the amount of time you hold that connection active/keep the data in memory.

    Having you explicitly call the .DataBind() method makes it possible to support scenarios at both ends of the spectrum.

提交回复
热议问题