0

コードの2つの部分に違いがあるのだろうか:

   //1
    public partial class MyPage : System.Web.UI.Page
    {

     public override void DataBind()
     {
        base.DataBind();
        this.myTableGrid.SetupDataSource();
     }

    }

    //2
    public partial class MyPage : System.Web.UI.Page
    {

     public void Page_DataBind(object e, EventArgs e)
     {
        this.myTableGrid.SetupDataSource();
     }

    }
4

1 に答える 1

0

Essentially, they both accomplish the same task. Your Page_DataBind method will be called in base.DataBind() so it might save a teeny tiny (i.e. negligible) amount of cpu clicks as it doesn't have to call the method delegate.

One difference in example 2 is that you can call that method, without having to call DataBind() on the page.

This may prove useful if have a lot of controls on your page but only want to databind a few of them (as databinding can prove to be a costly operation, given that it makes heavy use of reflection and type casts).

于 2012-06-06T14:59:59.900 に答える